Hi,
I have a set of functions:
f1 :: DBRecord - Maybe Int
f2 :: Int - IO Maybe DBRecord
f3 :: DBRecord - Maybe Int
The odd numbered functions are field accessors, accessing a field that
might hold an identifier for another record. The even numbered functions
are record fetch functions that
Hey Mark,
How can I concisely compose these functions without having to write
a cascade of case statements such as:
case f1 rec1 of
Nothing - return Nothing
Just id1 - do
rec2 - f2 id2
return $ case rec2 of
Wait, there are two monads in scene here, IO and Maybe.
The right solution is to compose them indeed. One could use the
MaybeT monad transformer defined in the 'All about monads' tutorial
[1], or we could just define the IOmaybe monad:
import Data.Traversable (mapM)
newtype IOMaybe a =
Once I start needing to combine Maybe with other monads, I usually
take a moment to generalize the appropriate Maybe parts to MonadError
e m = m. Then we can just use the (ErrorT e IO) monad.
Nick
On 12/16/06, Pepe Iborra [EMAIL PROTECTED] wrote:
Wait, there are two monads in scene here, IO