Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  State monad (Daniel Fischer)
   2. Re:  Monad Transformer Type Signatures (snk_kid)


----------------------------------------------------------------------

Message: 1
Date: Tue, 15 Feb 2011 13:48:46 +0100
From: Daniel Fischer <daniel.is.fisc...@googlemail.com>
Subject: Re: [Haskell-beginners] State monad
To: beginners@haskell.org
Cc: Britt Anderson <britt.uwater...@gmail.com>
Message-ID: <201102151348.46883.daniel.is.fisc...@googlemail.com>
Content-Type: text/plain;  charset="utf-8"

On Monday 14 February 2011 19:23:43, Britt Anderson wrote:
> Actually, I can load the module and I have mtl. I just don't understand
> why I can use State as a data constructor, but the inverse of runState,
> i.e. state works just fine. Has this library/package been reconfigured
> from when most people were writing tutorials?

Exactly that. As of mtl-2.*, mtl is now a wrapper around transformers and 
no longer an independent library.
One change which broke a lot of tutorials (and some code) is that State is 
no longer a separate datatype. (State s) is now a type synonym for
(StateT s Identity), similarly for Reader, Writer. Those parts of the 
tutorials whcih don't use the data-constructor should work unchanged, 
though.



------------------------------

Message: 2
Date: Tue, 15 Feb 2011 13:12:51 +0000 (UTC)
From: snk_kid <korca...@hotmail.com>
Subject: Re: [Haskell-beginners] Monad Transformer Type Signatures
To: beginners@haskell.org
Message-ID: <loom.20110215t140447...@post.gmane.org>
Content-Type: text/plain; charset=us-ascii

Brent Yorgey <byorgey <at> seas.upenn.edu> writes:

> 
> On Mon, Feb 14, 2011 at 02:10:13PM -0500, Britt Anderson wrote:
> > I am looking at code from a tutorial that has the following type
> > signature for a function:
> > 
> > getScreen :: MonadReader AppConfig m => m Surface
> > 
> > AppConfig is a data structure that was defined previously. My question
> > is how am I to interpret this type signature? Is it any m belonging to
> > the MonadReader AppConfig class? 
> 
> Yes.  And there will be an instance for MonadReader AppConfig m
> exactly when m carries around an implicit "read-only" AppConfig value,
> available for querying with the 'ask' and 'asks' functions.
> 
> > Since I can't see any instance of the MonadReader
> > Class being defined for MonadReader AppConfig I am puzzled.
> 
> Typically what you will see is some concrete monad later being defined
> in terms of ReaderT AppConfig, which will automatically give it an
> appropriate MonadReader instance, allowing users of the monad to query
> the AppConfig.
> 
> > I would appreciate some clarification or a pointer to a prior
> > discussion of this issue. I have tried to look on my own.
> 
> I recommend reading Cale Gibbard's article "How to use monad
> transformers"... except at the moment I can't seem to find it
> anywhere. =(
> 
> -Brent
> 
> 

This looks like my code, just to add this is this requires Flexible Contexts
extension (for which I believe became part of the Haskell 2010 standard if I
remember correctly) I didn't need to write it this way, I could have used the
specific monad transformer stack that I use. The only reason to use a typeclass
is for more generic code, it makes the code decoupled from a specific monad 
stack (any monad type for that matter, any which implements 
MonadReader AppConfig).

Also note that at the time I didn't know much about first-class record libraries
like fclabels which could have reduce repeative boiler-plate code I wrote in
later tutorials.




------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 32, Issue 32
*****************************************

Reply via email to