fork download
  1. {-# LANGUAGE MonadComprehensions #-}
  2. import Control.Applicative
  3.  
  4. foo x = ["0"| x == 0]
  5. <|> ["1"| x == 1]
  6. <|> ["bus number " ++ show x | x >= 100, x < 200] :: Maybe String
  7.  
  8. main = mapM_ print $ [foo 0, foo 1, foo 50, foo 150, foo 300]
Success #stdin #stdout 0s 5692KB
stdin
Standard input is empty
stdout
Just "0"
Just "1"
Nothing
Just "bus number 150"
Nothing