From: Jim Pryor Date: Sun, 12 Dec 2010 23:13:10 +0000 (-0500) Subject: tweak transformers X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=commitdiff_plain;h=369a3c9c051123eb7ff351eef8dab42480bc43f4;ds=sidebyside tweak transformers Signed-off-by: Jim Pryor --- diff --git a/monad_transformers.mdwn b/monad_transformers.mdwn index d6a22982..53a16899 100644 --- a/monad_transformers.mdwn +++ b/monad_transformers.mdwn @@ -1,6 +1,7 @@ [[!toc]] -##Multi-layered monadic boxes## +Multi-layered monadic boxes +=========================== So far, we've defined monads as single-layered boxes. Though in the Groenendijk, Stokhof, and Veltman homework, we had to figure out how to combine Reader, State, and Set monads in an ad-hoc way. In practice, one often wants to combine the abilities of several monads. Corresponding to each monad like Reader, there's a corresponding ReaderT **monad transformer**. That takes an existing monad M and wraps Readerish monad packaging around it. The way these are defined parallels the way the single-layer versions are defined. For example, here's the Reader monad: @@ -116,6 +117,15 @@ As best we know, figuring out how a monad transformer should be defined is still Apart from whose interface is outermost, the behavior of a StateT(Maybe) and a MaybeT(State) will partly coincide. But in certain crucial respects they will diverge, and you need to think carefully about which behavior you want and what the appropriate layering is for your needs. (MORE...) + +Further Reading +--------------- + +* This is excellent, everyone should read: [Monad Transformers Step by Step](http://www.grabmueller.de/martin/www/pub/Transformers.pdf) + +* Read Part III of [All About Monads](http://web.archive.org/web/20071106232016/haskell.org/all_about_monads/html/introIII.html). This link is to an archived version, the main link to haskell.org seems to be broken. Some but not all of this site has been [absorbed into the Haskell wikibook](http://en.wikibooks.org/wiki/Haskell/Monad_transformers). + + Tree Monads =========== @@ -195,18 +205,10 @@ You have to instead say something like this: - : ('_a, int) Tree_monad.m = -Further Reading ---------------- - -* This is excellent, everyone should read: [Monad Transformers Step by Step](http://www.grabmueller.de/martin/www/pub/Transformers.pdf) - -* Read Part III of [All About Monads](http://web.archive.org/web/20071106232016/haskell.org/all_about_monads/html/introIII.html). This link is to an archived version, the main link to haskell.org seems to be broken. Some but not all of this site has been [absorbed into the Haskell wikibook](http://en.wikibooks.org/wiki/Haskell/Monad_transformers). - How is all this related to our tree\_monadize function? ------------------------------------------------------- - Recall our earlier definition of `tree_monadize`, specialized for the Reader monad: let rec tree_monadize (f : 'a -> 'b reader) (t : 'a tree) : 'b tree reader =