map/filter with foldr
第七课的小练习:http://www.cs.nott.ac.uk/~gmh/chapter7.ppt
> map' :: (a -> b) -> [a] -> [b]
> map' f = foldr (\a b -> (f a) : b) []
>
> filter' :: (a -> Bool) -> [a] -> [a]
> filter' f = foldr f' [] where
> f' a b = if f a then a:b else b
标签: haskell
0 Comments:
发表评论
<< Home