[Haskell-cafe] Re: nested maybes

Martin Huschenbett huschi at gmx.org
Sun Feb 4 18:47:33 EST 2007


I've often got the same pattern with nested Maybes but inside the IO 
monad (sure this could be every other monad too). Assuming that I've got 

getInput :: IO (Maybe Input)
processInput :: Input -> IO (Maybe Result)
printError :: IO ()
printResult :: Result -> IO ()

I observed me writing something like

main :: IO ()
main = do
   minput <- getInput
   case minput of
     Nothing -> printError
     Just input -> do
       mresult <- processInput input
       case mresult of
         Nothing -> printError
         Just result -> printResult result

several times. But to my mind this looks very imperative and I hope it 
can be done more functional. If there is any way, please let me know.



More information about the Haskell-Cafe mailing list