fork download
  1. ifM :: Monad m => m Bool -> m a -> m a -> m a
  2. ifM act t e = do
  3. b <- act
  4. if b then t else e
  5.  
  6. anAction = return False
  7. otherAction = return True
  8.  
  9. infixl 4 <?>
  10.  
  11. (<?>) :: Monad m => m Bool -> m a -> m a -> m a
  12. (<?>) = ifM
  13.  
  14. main :: IO String
  15. main = anAction <?> do
  16. putStrLn "branch a"
  17. return "a"
  18. $ otherAction <?> do
  19. putStrLn "branch b"
  20. return "b"
  21. $ return "none"
Success #stdin #stdout 0s 4684KB
stdin
Standard input is empty
stdout
branch b