Re: [Haskell-cafe] Composing monads

2007-11-23 Thread Jules Bean
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

[Haskell-cafe] Composing monads

2007-11-22 Thread Maurí­cio
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

Re: [Haskell-cafe] Composing monads

2007-11-22 Thread Jonathan Cast
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

Re: [Haskell-cafe] Composing monads

2007-11-22 Thread Brandon S. Allbery KF8NH
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 (=)

Re: [Haskell-cafe] Composing monads

2007-11-22 Thread Brent Yorgey
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

[Haskell-cafe] Composing monads (sort of)

2006-12-16 Thread Mark Wassell
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

Re: [Haskell-cafe] Composing monads (sort of)

2006-12-16 Thread Chris Eidhof
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

Re: [Haskell-cafe] Composing monads (sort of)

2006-12-16 Thread Pepe Iborra
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 =

Re: Re: [Haskell-cafe] Composing monads (sort of)

2006-12-16 Thread Nicolas Frisby
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