{-# LANGUAGE MonadComprehensions #-}import Control.Applicative foo x = ["0"| x == 0] <|> ["1"| x == 1] <|> ["bus number " ++ show x | x >= 100, x < 200] :: Maybe String main = mapM_ print $ [foo 0, foo 1, foo 50, foo 150, foo 300]
Standard input is empty
Just "0" Just "1" Nothing Just "bus number 150" Nothing
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!