From: simonpj Date: Mon, 30 Sep 2002 13:42:01 +0000 (+0000) Subject: [project @ 2002-09-30 13:42:01 by simonpj] X-Git-Tag: Approx_11550_changesets_converted~1603 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=67d593b8531b094ceef7c229e00b086011aef7c0;p=ghc-hetmet.git [project @ 2002-09-30 13:42:01 by simonpj] Move mdo section --- diff --git a/ghc/docs/users_guide/glasgow_exts.sgml b/ghc/docs/users_guide/glasgow_exts.sgml index b98d10b..6001ed9 100644 --- a/ghc/docs/users_guide/glasgow_exts.sgml +++ b/ghc/docs/users_guide/glasgow_exts.sgml @@ -2628,6 +2628,84 @@ qualifier list has just one element, a boolean expression. + + + +The recursive do-notation + + + The recursive do-notation (also known as mdo-notation) is implemented as described in +"A recursive do for Haskell", +Levent Erkok, John Launchbury", +Haskell Workshop 2002, pages: 29-37. Pittsburgh, Pennsylvania. + + +The do-notation of Haskell does not allow recursive bindings, +that is, the variables bound in a do-expression are visible only in the textually following +code block. Compare this to a let-expression, where bound variables are visible in the entire binding +group. It turns out that several applications can benefit from recursive bindings in +the do-notation, and this extension provides the necessary syntactic support. + + +Here is a simple (yet contrived) example: + + +justOnes = mdo xs <- Just (1:xs) + return xs + + +As you can guess justOnes will evaluate to Just [1,1,1,.... + + + +The MonadRec library introduces the MonadRec class. It's definition is: + + +class Monad m => MonadRec m where + mfix :: (a -> m a) -> m a + + +The function mfix +dictates how the required recursion operation should be performed. If recursive bindings are required for a monad, +then that monad must be declared an instance of the MonadRec class. +For details, see the above mentioned reference. + + +The MonadRec library automatically declares List, Maybe, IO, and +state monads (both lazy and strict) as instances of the MonadRec class. + + +There are three important points in using the recursive-do notation: + + +The recursive version of the do-notation uses the keyword mdo (rather +than do). + + + +If you want to declare an instance of the MonadRec class for one of +your own monads, or you need to refer to the class name MonadRec in any other way (for instance in +writing a type constraint), then your program should import Control.Monad.MonadRec. +Otherwise, you don't need to import any special libraries to use the mdo-notation. That is, +as long as you only use the predefined instances mentioned above, the mdo-notation will +be automatically available. (Note: This differs from the Hugs implementation, where +MonadRec should always be imported.) + + + +As with other extensions, ghc should be given the flag -fglasgow-exts + + + + + + +The web page: http://www.cse.ogi.edu/PacSoft/projects/rmb +contains up to date information on recursive monadic bindings. + + + + @@ -4025,81 +4103,6 @@ instances is most interesting. - -The recursive do-notation - - - The recursive do-notation (a.k.a. mdo-notation) is implemented as described in -"A recursive do for Haskell", -Levent Erkok, John Launchbury", -Haskell Workshop 2002, pages: 29-37. Pittsburgh, Pennsylvania. - - -The do-notation of Haskell does not allow recursive bindings, -that is, the variables bound in a do-expression are visible only in the textually following -code block. Compare this to a let-expression, where bound variables are visible in the entire binding -group. It turns out that several applications can benefit from recursive bindings in -the do-notation, and this extension provides the necessary syntactic support. - - -Here is a simple (yet contrived) example: - - -justOnes = mdo xs <- Just (1:xs) - return xs - - -As you can guess justOnes will evaluate to Just [1,1,1,.... - - - -The MonadRec library introduces the MonadRec class. It's definition is: - - -class Monad m => MonadRec m where - mfix :: (a -> m a) -> m a - - -The function mfix -dictates how the required recursion operation should be performed. If recursive bindings are required for a monad, -then that monad must be declared an instance of the MonadRec class. -For details, see the above mentioned reference. - - -The MonadRec library automatically declares List, Maybe, IO, and -state monads (both lazy and strict) as instances of the MonadRec class. - - -There are three important points in using the recursive-do notation: - - -The recursive version of the do-notation uses the keyword mdo (rather -than do). - - - -If you want to declare an instance of the MonadRec class for one of -your own monads, or you need to refer to the class name MonadRec in any other way (for instance in -writing a type constraint), then your program should import Control.Monad.MonadRec. -Otherwise, you don't need to import any special libraries to use the mdo-notation. That is, -as long as you only use the predefined instances mentioned above, the mdo-notation will -be automatically available. (Note: This differs from the Hugs implementation, where -MonadRec should always be imported.) - - - -As with other extensions, ghc should be given the flag -fglasgow-exts - - - - - - -The web page: http://www.cse.ogi.edu/PacSoft/projects/rmb -contains up to date information on recursive monadic bindings. - - -