From: simonpj Date: Fri, 7 Mar 2003 13:36:59 +0000 (+0000) Subject: [project @ 2003-03-07 13:36:59 by simonpj] X-Git-Tag: Approx_11550_changesets_converted~1083 X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=f3d376e190102c5e92f81a9f37c2f716f0c731d8 [project @ 2003-03-07 13:36:59 by simonpj] Update docs on class method types --- diff --git a/ghc/docs/users_guide/glasgow_exts.sgml b/ghc/docs/users_guide/glasgow_exts.sgml index 9137ec2..0956fd1 100644 --- a/ghc/docs/users_guide/glasgow_exts.sgml +++ b/ghc/docs/users_guide/glasgow_exts.sgml @@ -959,38 +959,19 @@ classes: exploring the design space (Simon Peyton Jones, Mark Jones, Erik Meijer). - -I'd like to thank people who reported shorcomings in the GHC 3.02 -implementation. Our default decisions were all conservative ones, and -the experience of these heroic pioneers has given useful concrete -examples to support several generalisations. (These appear below as -design choices not implemented in 3.02.) - - - -I've discussed these notes with Mark Jones, and I believe that Hugs -will migrate towards the same design choices as I outline here. -Thanks to him, and to many others who have offered very useful -feedback. - - + Types -There are the following restrictions on the form of a qualified -type: - - - +GHC imposes the following restrictions on the form of a qualified +type, whether declared in a type signature +or inferred. Consider the type: forall tv1..tvn (c1, ...,cn) => type - - - (Here, I write the "foralls" explicitly, although the Haskell source language omits them; in Haskell 1.4, all the free type variables of an explicit source-language type signature are universally quantified, @@ -1005,11 +986,15 @@ in GHC, you can give the foralls if you want. See ) +on the type variables free in type. The reason for this is that a value with a type that does not obey this restriction could not be used without introducing -ambiguity. Here, for example, is an illegal type: +ambiguity. +Here, for example, is an illegal type: @@ -1064,10 +1049,6 @@ territory free in case we need it later. - -These restrictions apply to all types, whether declared in a type signature -or inferred. - Unlike Haskell 1.4, constraints in types do not have to be of @@ -1154,56 +1135,14 @@ be acyclic. So these class declarations are OK: - - - - In the signature of a class operation, every constraint -must mention at least one type variable that is not a class type -variable. - -Thus: - - - - class Collection c a where - mapC :: Collection c b => (a->b) -> c a -> c b - - - -is OK because the constraint (Collection a b) mentions -b, even though it also mentions the class variable -a. On the other hand: - - - - class C a where - op :: Eq a => (a,b) -> (a,b) - - -is not OK because the constraint (Eq a) mentions on the class -type variable a, but not b. However, any such -example is easily fixed by moving the offending context up to the -superclass context: - - - - class Eq a => C a where - op ::(a,b) -> (a,b) - - - -A yet more relaxed rule would allow the context of a class-op signature -to mention only class type variables. However, that conflicts with -Rule 1(b) for types above. - - - - The type of each class operation must mention all of -the class type variables. For example: + All of the class type variables must be reachable (in the sense +mentioned in ) +from the free varibles of each method type +. For example: