Created
February 4, 2015 12:05
-
-
Save shigemk2/3be4d574fb0e544b20bc to your computer and use it in GitHub Desktop.
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
| reverse' :: [a] -> [a] | |
| reverse' = foldl (\acc x -> x : acc) [] | |
| reverse'' :: [a] -> [a] | |
| reverse'' = foldl (flip (:)) [] | |
| product' :: (Num a) => [a] -> a | |
| product' = foldl (*) 1 | |
| filter' :: (a -> Bool) -> [a] -> [a] | |
| filter' p = foldr (\x acc -> if p x then x : acc else acc) [] | |
| last' :: [a] -> a | |
| last' = foldl1 (\_ x -> x) | |
| main = do | |
| print $ reverse' [1,2,3,4,5] | |
| print $ reverse'' [1,2,3,4,5] | |
| print $ product' [1,2,3,4,5] | |
| print $ filter' (< 3) [1,2,3,4,5] | |
| print $ last' [1,2,3,4,5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment