Skip to content

Instantly share code, notes, and snippets.

@lotz84
Created November 2, 2015 13:22
Show Gist options
  • Save lotz84/7024765e609b952bf2a1 to your computer and use it in GitHub Desktop.
Save lotz84/7024765e609b952bf2a1 to your computer and use it in GitHub Desktop.
import Control.Monad.Trans.Maybe
import Control.Monad.IO.Class
import Data.List
env :: [(String, Int)]
env = [("x", 1), ("y", 2), ("z", 3)]
main :: IO ()
main = do
result <- runMaybeT $ do
n <- mb $ lookup "x" env
q <- liftIO $ getLine
mb $ if q /= "q" then Just q else Nothing
putStrLn $ maybe "quit!" id $ result
where
mb = MaybeT . pure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment