Created
June 7, 2016 17:04
-
-
Save taojang/90122c3033b0fd4bd22deae752ef2135 to your computer and use it in GitHub Desktop.
Some freaky point free stuff of chapter 10 of the haskell book
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
| module Chapter10 where | |
| -- from Mark & Amr | |
| myOr :: [Bool] -> Bool | |
| myOr = foldr (||) False | |
| myAny :: (a -> Bool) -> [a] -> Bool | |
| myAny = (myOr .) . map | |
| myReverse :: [a] -> [a] | |
| myReverse = foldl (flip (:)) [] | |
| myMap :: (a -> b) -> [a] -> [b] | |
| myMap f = foldr ((:) . f) [] | |
| myMap' :: (a -> b) -> [a] -> [b] | |
| myMap' = flip foldr [] . ((:) .) |
Btw, I have found a point-free version for myAny that uses foldr.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not sure that's how a point-free
myAnyshould look like. From what I understand, you'd map through the entire list and then call myOr on the elements which would not be optimal? I think the point of the exercise is that it needs to be point-free but still take advantage of fold capabilities to stop early.