Maurício wrote:
Hi,
If I have two computations a-IO b
and b-IO c, can I join them to
get an a-IO c computation? I imagine
something like a liftM dot operator.
You've already been shown the = operator and how to define it from =
by other answers.
Just for variety, here is how you would
Hi,
If I have two computations a-IO b
and b-IO c, can I join them to
get an a-IO c computation? I imagine
something like a liftM dot operator.
Thanks,
Maurício
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
On 22 Nov 2007, at 10:17 AM, Maurí cio wrote:
Hi,
If I have two computations a-IO b
and b-IO c, can I join them to
get an a-IO c computation? I imagine
something like a liftM dot operator.
This is called Kleisli composition, by the way; it's defined as (=)
in Control.Monad.
jcc
On Nov 22, 2007, at 13:17 , Maurí cio wrote:
If I have two computations a-IO b
and b-IO c, can I join them to
get an a-IO c computation? I imagine
something like a liftM dot operator.
If you have GHC 6.8.1, this is the Kleisli composition operator (=)
in Control.Monad. (There is also (=)
On Nov 22, 2007 1:22 PM, Jonathan Cast [EMAIL PROTECTED] wrote:
On 22 Nov 2007, at 10:17 AM, Maurí cio wrote:
Hi,
If I have two computations a-IO b
and b-IO c, can I join them to
get an a-IO c computation? I imagine
something like a liftM dot operator.
This is called Kleisli
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