monad transformers

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

monad transformers

Michael Mossey
In Martin Grabmuller's tutorial "Monad Transformers Step by Step", found here

http://user.cs.tu-berlin.de/~magr/pub/Transformers.pdf

he gives an example of composing ErrorT, StateT, ReaderT, and WriterT. Early in
the paper, where he composes just ErrorT and ReaderT

     type Eval3 a = ReaderT Env (ErrorT String Identity) a

he uses 'ask' and 'throwError' in some example code. I notice that he doesn't
have to lift throwError into the ErrorT monad. Why is this? Do I misunderstand
something about monad transformers? Is it a convenience definition of throwError?

Same thing the rest of the paper. I don't see anywhere he lifts anything.

Thanks,
Mike



Reply | Threaded
Open this post in threaded view
|

Constructors as functions (was monad transformers)

Michael Mossey
Michael P Mossey wrote:
> In Martin Grabmuller's tutorial "Monad Transformers Step by Step", found
> here
>
> http://user.cs.tu-berlin.de/~magr/pub/Transformers.pdf
>

Additional question: in this paper he uses a data constructor in an interesting
way: back-quoting it to make it an operator. I thought, "Huh, a constructor is a
lot like a function?" I did some experiments and found that I can map a
constructor over a list and I can compose a constructor with other functions.
Cool. So is a constructor a function, in every sense?

Thanks,
Mike
Reply | Threaded
Open this post in threaded view
|

monad transformers

Brandon S Allbery KF8NH
In reply to this post by Michael Mossey
On Aug 14, 2009, at 20:55 , Michael P Mossey wrote:

> In Martin Grabmuller's tutorial "Monad Transformers Step by Step",  
> found here
>
> http://user.cs.tu-berlin.de/~magr/pub/Transformers.pdf
>
> he gives an example of composing ErrorT, StateT, ReaderT, and  
> WriterT. Early in the paper, where he composes just ErrorT and ReaderT
>
>    type Eval3 a = ReaderT Env (ErrorT String Identity) a
>
> he uses 'ask' and 'throwError' in some example code. I notice that  
> he doesn't have to lift throwError into the ErrorT monad. Why is  
> this? Do I misunderstand something about monad transformers? Is it a  
> convenience definition of throwError?


Look for definitions of the form

 > instance MonadReader Eval3 where ...
 > instance MonadError Eval3 where ...

These effectively "import" definitions of ask, throwError, etc. with  
implicit lifting.

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [hidden email]
system administrator [openafs,heimdal,too many hats] [hidden email]
electrical and computer engineering, carnegie mellon university    KF8NH


-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/beginners/attachments/20090814/9417d865/PGP.bin
Reply | Threaded
Open this post in threaded view
|

Constructors as functions (was monad transformers)

Isaac Dupree-3
In reply to this post by Michael Mossey
Michael P Mossey wrote:

> Michael P Mossey wrote:
>> In Martin Grabmuller's tutorial "Monad Transformers Step by Step",
>> found here
>>
>> http://user.cs.tu-berlin.de/~magr/pub/Transformers.pdf
>>
>
> Additional question: in this paper he uses a data constructor in an
> interesting way: back-quoting it to make it an operator. I thought,
> "Huh, a constructor is a lot like a function?" I did some experiments
> and found that I can map a constructor over a list and I can compose a
> constructor with other functions. Cool. So is a constructor a function,
> in every sense?

Yes.  In expressions, a constructor is a function, no more and no less
(albeit with some weird capitalization).  Constructors however, can
*also* be used in pattern-matching, unlike functions.  That's the
(only?) special thing about them.

-Isaac