相关疑难解决方法(0)

haskell的foldr总是采用双参数lambda吗?

Haskell newb在这里

我正在研究haskell中的这个问题:

(**) Eliminate consecutive duplicates of list elements.
If a list contains repeated elements they should be replaced with a single copy of the element. The order of the elements should not be changed.

Example:
* (compress '(a a a a b c c a a d e e e e))
(A B C A D E)
Run Code Online (Sandbox Code Playgroud)

解决方案(我必须查找)使用foldr:

compress' :: (Eq a) => [a] -> [a]
compress' xs = foldr (\x acc -> if x == (head acc) …
Run Code Online (Sandbox Code Playgroud)

haskell fold

8
推荐指数
2
解决办法
3328
查看次数

标签 统计

fold ×1

haskell ×1