X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=docs%2Fusers_guide%2Fghci.xml;h=06eb348bfb562b1b58275c992e66708befde9c70;hb=1f28aaa6116d9cb90966b1bb6cdcbe52fe938867;hp=7f3fd32ce9cc4a74d89b9c0cfaa521bd90eea5b0;hpb=a8e681c1e8aa4bc602714ff61583cd4e969d7187;p=ghc-hetmet.git
diff --git a/docs/users_guide/ghci.xml b/docs/users_guide/ghci.xml
index 7f3fd32..06eb348 100644
--- a/docs/users_guide/ghci.xml
+++ b/docs/users_guide/ghci.xml
@@ -747,24 +747,79 @@ it <- e
standard rules take each group of constraints (C1 a, C2 a, ..., Cn
a) for each type variable a, and defaults the
type variable if
-
- The type variable a
- appears in no other constraints
- All the classes Ci are standard.
- At least one of the classes Ci is
- numeric.
-
- At the GHCi prompt, the second and third rules are relaxed as follows
- (differences italicised):
-
- All of the classes
- Ci are single-parameter type classes.
- At least one of the classes Ci is
- numeric, or is Show,
- Eq, or Ord.
-
- The same type-default behaviour can be enabled in an ordinary Haskell
- module, using the flag -fextended-default-rules.
+
+
+
+ The type variable a appears in no
+ other constraints
+
+
+
+
+ All the classes Ci are standard.
+
+
+
+
+ At least one of the classes Ci is
+ numeric.
+
+
+
+ At the GHCi prompt, or with GHC if the
+ -fextended-default-rules flag is given,
+ the following additional differences apply:
+
+
+
+ Rule 2 above is relaxed thus:
+ All of the classes
+ Ci are single-parameter type classes.
+
+
+
+
+ Rule 3 above is relaxed this:
+ At least one of the classes Ci is
+ numeric, or is Show,
+ Eq, or
+ Ord.
+
+
+
+
+ The unit type () is added to the
+ start of the standard list of types which are tried when
+ doing type defaulting.
+
+
+
+ The last point means that, for example, this program:
+
+main :: IO ()
+main = print def
+
+instance Num ()
+
+def :: (Num a, Enum a) => a
+def = toEnum 0
+
+ prints () rather than 0 as the
+ type is defaulted to () rather than
+ Integer.
+
+
+ The motivation for the change is that it means IO a
+ actions default to IO (), which in turn means that
+ ghci won't try to print a result when running them. This is
+ particularly important for printf, which has an
+ instance that returns IO a.
+ However, it is only able to return
+ undefined
+ (the reason for the instance having this type is to not require
+ extensions to the class system), so if the type defaults to
+ Integer then ghci gives an error when running a
+ printf.