[Update manual: tidy up instances, say more about type families in instance decls
simonpj@microsoft.com**20081015080509] {
hunk ./docs/users_guide/flags.xml 935
- Enable type synonyms.
+ Enable type synonyms.
hunk ./docs/users_guide/glasgow_exts.xml 3250
-
-Relaxed rules for instance declarations
-
hunk ./docs/users_guide/glasgow_exts.xml 3259
+
+Relaxed rules for the instance head
+
hunk ./docs/users_guide/glasgow_exts.xml 3265
-C is the class, T is a type constructor,
+C is the class, T is a data type constructor,
hunk ./docs/users_guide/glasgow_exts.xml 3267
-Furthermore, the assertions in the context of the instance declaration
+GHC relaxes these rules in two ways.
+
+
+
+The flag allows the head of the instance
+declaration to mention arbitrary nested types.
+For example, this becomes a legal instance declaration
+
+ instance C (Maybe Int) where ...
+
+See also the rules on overlap.
+
+
+With the flag, instance heads may use type
+synonyms. As always, using a type synonym is just shorthand for
+writing the RHS of the type synonym definition. For example:
+
+
+
+ type Point = (Int,Int)
+ instance C Point where ...
+ instance C [Point] where ...
+
+
+
+is legal. However, if you added
+
+
+
+ instance C (Int,Int) where ...
+
+
+
+as well, then the compiler will complain about the overlapping
+(actually, identical) instance declarations. As always, type synonyms
+must be fully applied. You cannot, for example, write:
+
+
+ type P a = [[a]]
+ instance Monad P where ...
+
+
+
+
+
+
+
+
+Relaxed rules for instance contexts
+
+In Haskell 98, the assertions in the context of the instance declaration
hunk ./docs/users_guide/glasgow_exts.xml 3321
+
hunk ./docs/users_guide/glasgow_exts.xml 3323
-The flag loosens these restrictions
-considerably. Firstly, multi-parameter type classes are permitted. Secondly,
-the context and head of the instance declaration can each consist of arbitrary
+The flag relaxes this rule, as well
+as the corresponding rule for type signatures (see ).
+With this flag the context of the instance declaration can each consist of arbitrary
hunk ./docs/users_guide/glasgow_exts.xml 3623
-
-Type synonyms in the instance head
-
-
-Unlike Haskell 98, instance heads may use type
-synonyms. (The instance "head" is the bit after the "=>" in an instance decl.)
-As always, using a type synonym is just shorthand for
-writing the RHS of the type synonym definition. For example:
-
-
-
- type Point = (Int,Int)
- instance C Point where ...
- instance C [Point] where ...
-
-
-
-is legal. However, if you added
-
-
-
- instance C (Int,Int) where ...
-
-
-
-as well, then the compiler will complain about the overlapping
-(actually, identical) instance declarations. As always, type synonyms
-must be fully applied. You cannot, for example, write:
-
-
-
- type P a = [[a]]
- instance Monad P where ...
-
-
-
-This design decision is independent of all the others, and easily
-reversed, but it makes sense to me.
-
-
-
hunk ./docs/users_guide/glasgow_exts.xml 4341
+
+ Type families and instance declarations
+ Type families require us to extend the rules for
+ the form of instance heads, which are given
+ in .
+ Specifically:
+
+ Data type families may appear in an instance head
+ Type synonym families may not appear (at all) in an instance head
+
+The reason for the latter restriction is that there is no way to check for. Consider
+
+ type family F a
+ type instance F Bool = Int
+
+ class C a
+
+ instance C Int
+ instance C (F a)
+
+Now a constraint (C (F Bool)) would match both instances.
+The situation is especially bad because the type instance for F Bool
+might be in another module, or even in a module that is not yet written.
+
+
}