
4 Feb
2007
4 Feb
'07
6:47 p.m.
Hi, 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 functions: 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. Regards, Martin.