Last active
October 19, 2017 06:46
-
-
Save laserpants/478a2b2b81f9fb20d723cc4707147538 to your computer and use it in GitHub Desktop.
Haskell ternary operator.
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 Main where | |
(.?.) :: Bool -> (a, a) -> a | |
(.?.) True = fst | |
(.?.) False = snd | |
infixl 3 .?. | |
(>:<) :: a -> b -> (a, b) | |
(>:<) = (,) | |
main :: IO () | |
main = do | |
print $ 3 == 5 .?. "yes" >:< "no" -- "no" | |
print $ 5 > 3 .?. "yes" >:< "no" -- "yes" | |
print $ 3 - 3 == 0 .?. "yes" >:< "no" -- "yes" | |
print $ null [] .?. "yes" >:< "no" -- "yes" | |
print $ null [1] .?. "yes" >:< "no" -- "no" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment