
12 Nov
2007
12 Nov
'07
6:59 p.m.
I wanted something that would work like liftM but with IO as well, so something like this:
liftM ((+) 1) $ Just 1 Just 2
but with the function lifted being of type (a -> IO b). so I came up with maybeIO::(a -> IO b) -> (Maybe a -> IO (Maybe b)) maybeIO ff = (\ aa -> case aa of Nothing -> return $ Nothing Just vv -> do rv <- ff vv return $ Just rv) incIO:: Int -> IO Int incIO ii = return $ ii + 1
maybeIO incIO $ Just 1 Just 2
works just like I want it to. But isn't this something that a monad transformer should be able to do?