Skip to content

Instantly share code, notes, and snippets.

@taojang
Created June 7, 2016 17:04
Show Gist options
  • Select an option

  • Save taojang/90122c3033b0fd4bd22deae752ef2135 to your computer and use it in GitHub Desktop.

Select an option

Save taojang/90122c3033b0fd4bd22deae752ef2135 to your computer and use it in GitHub Desktop.
Some freaky point free stuff of chapter 10 of the haskell book
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 [] . ((:) .)
@galderz
Copy link

galderz commented Jul 30, 2016

Not sure that's how a point-free myAny should 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.

@galderz
Copy link

galderz commented Jul 30, 2016

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