From: erkok Date: Sat, 28 Sep 2002 07:12:55 +0000 (+0000) Subject: [project @ 2002-09-28 07:12:55 by erkok] X-Git-Tag: Approx_11550_changesets_converted~1615 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;ds=sidebyside;h=a4dab43e59b9839cc86a4e2263ed573be851904f;p=ghc-hetmet.git [project @ 2002-09-28 07:12:55 by erkok] clarifications on the mdo documentation. --- diff --git a/ghc/docs/users_guide/glasgow_exts.sgml b/ghc/docs/users_guide/glasgow_exts.sgml index bcc7d1e..b98d10b 100644 --- a/ghc/docs/users_guide/glasgow_exts.sgml +++ b/ghc/docs/users_guide/glasgow_exts.sgml @@ -4045,12 +4045,31 @@ the do-notation, and this extension provides the necessary syntactic support. Here is a simple (yet contrived) example: -import Control.Monad.MonadRec - 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: @@ -4059,7 +4078,13 @@ than do). -The scripts using mdo should import Control.Monad.MonadRec +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.) @@ -4068,23 +4093,6 @@ As with other extensions, ghc should be given the flag -fglasgow-exts - -The MonadRec library introduces the MonadRec class. It's definition is: - - -class Monad m => MonadRec m where - mfix :: (a -> m a) -> m a - - -The MonadRec class declares the function mfix, -which dictates how the recursion should behave. 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 mentione reference. - - -The MonadRec library automatically declares List, Maybe, IO, and -state monads (both lazy and strict) as instances of the MonadRec class. - The web page: http://www.cse.ogi.edu/PacSoft/projects/rmb