Apple has type
apple :: [(a, a->b)] -> [b]
We could rewrite it as
apple ls = map (\(a, f) -> fa) ls
So itβs very convenient to write this with foldr ,
apple ls = foldr (\(a, f) rest -> fa : rest) [] ls
Or, we can rewrite this in pointfree
apple = foldr ( (:) . (uncurry . flip $ ($)) ) []
The reason for the parsing error is that _ is a special syntax for "variables that I don't need." This will allow you to write things like
foo _ _ _ _ a = a
And do not get an error about duplicate variables. Basically, we just populated _ start empty list and fixed a function to add to c instead of trying to apply it to a .
If I wanted to write this in the clearest way, then the original
apple = map . uncurry . flip $ ($)
Very nice.
source share