Created
October 26, 2009 20:07
-
-
Save Burgestrand/218987 to your computer and use it in GitHub Desktop.
Ternary operator for haskell
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
module Ternary where | |
-- | Ternary operator. | |
-- Usage: (i > 0) ? i $ 1 | |
(?) :: Bool -> a -> a -> a | |
True ? x = const x | |
False ? _ = id | |
-- | Higher order ternary operator. | |
-- Usage: (not . null) ?? "" $ "default" | |
(??) :: (a -> Bool) -> a -> a -> a | |
f ?? x = f x ? x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment