Created
November 18, 2015 18:44
-
-
Save blippy/225fc9f309490e0a97fa to your computer and use it in GitHub Desktop.
Haskell idiom for predicate lifting
This file contains 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
Suppose I want to use an argument twice, as for example in the expression: | |
(\x -> (pred1 x) and (pred2 x)) | |
Is there a shorter way of doing this? | |
liftA2 (&&) pred1 pred2 | |
You can be cute and use the applicative instance on functions: | |
(&&) <$> pred1 <*> pred2 | |
I would recommend against such cuteness however and just write out the arguments. | |
And here's the arrow implementation | |
(pred1 &&& pred2) >>> uncurry (&&) | |
You need Data.Tuple (for uncurry) and Data.Arrow. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment