X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=docs%2Fusers_guide%2Fglasgow_exts.xml;h=90333b42c457a0777ffed1a265d3e90ed15c1c9c;hb=73c987fea0bf61b543dcb176eea1b2cc785f9d9d;hp=053c4a93e1226d139051ba994f016b1dee1d632a;hpb=0ee3de0a4ed263648599dee5d94e00585c5584a2;p=ghc-hetmet.git
diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml
index 053c4a9..90333b4 100644
--- a/docs/users_guide/glasgow_exts.xml
+++ b/docs/users_guide/glasgow_exts.xml
@@ -717,9 +717,11 @@ qualifier list has just one element, a boolean expression.
The recursive do-notation (also known as mdo-notation) is implemented as described in
-"A recursive do for Haskell",
-Levent Erkok, John Launchbury",
+A recursive do for Haskell,
+by Levent Erkok, John Launchbury,
Haskell Workshop 2002, pages: 29-37. Pittsburgh, Pennsylvania.
+This paper is essential reading for anyone making non-trivial use of mdo-notation,
+and we do not repeat it here.
The do-notation of Haskell does not allow recursive bindings,
@@ -750,11 +752,18 @@ class Monad m => MonadFix m where
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 MonadFix class.
-For details, see the above mentioned reference.
+dictates how the required recursion operation should be performed. For example,
+justOnes desugars as follows:
+
+justOnes = mfix (\xs' -> do { xs <- Just (1:xs'); return xs }
+
+For full details of the way in which mdo is typechecked and desugared, see
+the paper A recursive do for Haskell.
+In particular, GHC implements the segmentation technique described in Section 3.2 of the paper.
+If recursive bindings are required for a monad,
+then that monad must be declared an instance of the MonadFix class.
The following instances of MonadFix are automatically provided: List, Maybe, IO.
Furthermore, the Control.Monad.ST and Control.Monad.ST.Lazy modules provide the instances of the MonadFix class
for Haskell's internal state monad (strict and lazy, respectively).
@@ -2810,9 +2819,24 @@ Suppose that from the RHS of f we get the constraint
GHC does not commit to instance (C), because in a particular
call of f, b might be instantiate
to Int, in which case instance (D) would be more specific still.
-So GHC rejects the program. If you add the flag ,
+So GHC rejects the program.
+(If you add the flag ,
GHC will instead pick (C), without complaining about
-the problem of subsequent instantiations.
+the problem of subsequent instantiations.)
+
+
+Notice that we gave a type signature to f, so GHC had to
+check that f has the specified type.
+Suppose instead we do not give a type signature, asking GHC to infer
+it instead. In this case, GHC will refrain from
+simplifying the constraint C Int [Int] (for the same reason
+as before) but, rather than rejecting the program, it will infer the type
+
+ f :: C Int b => [b] -> [b]
+
+That postpones the question of which instance to pick to the
+call site for f
+by which time more is known about the type b.
The willingness to be overlapped or incoherent is a property of