Created
June 4, 2012 21:46
-
-
Save jbpotonnier/2871039 to your computer and use it in GitHub Desktop.
map is just fold, or is it the other way around :P Is fold enough to have map, filter, and recursion?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foldlmap :: (a -> b) -> [a] -> [b] | |
foldlmap f = foldl (\ a b -> a ++ [f b]) [] | |
foldrmap :: (a -> b) -> [a] -> [b] | |
foldrmap f = foldr (\ a b -> (f a) : b) [] | |
main :: IO () | |
main = do | |
print $ foldlmap (*2) [0 .. 5] | |
print $ foldrmap (*2) [0 .. 5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment