From: simonpj Date: Mon, 5 Apr 2004 10:53:52 +0000 (+0000) Subject: [project @ 2004-04-05 10:53:52 by simonpj] X-Git-Tag: Initial_conversion_from_CVS_complete~1909 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=99655406c82829dfc9663fc545a0e134c49fb79f;p=ghc-hetmet.git [project @ 2004-04-05 10:53:52 by simonpj] Improve documentation about ambiguous types --- diff --git a/ghc/docs/users_guide/glasgow_exts.sgml b/ghc/docs/users_guide/glasgow_exts.sgml index 12e8284..ceb4882 100644 --- a/ghc/docs/users_guide/glasgow_exts.sgml +++ b/ghc/docs/users_guide/glasgow_exts.sgml @@ -1531,12 +1531,12 @@ 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. +A type variable a is "reachable" if it it appears +in the same constraint as either a type variable free in in +type, or another reachable type variable. +A value with a type that does not obey +this reachability restriction cannot be used without introducing +ambiguity; that is why the type is rejected. Here, for example, is an illegal type: @@ -1551,7 +1551,23 @@ would be introduced where tv is a fresh type variable, and applied to a dictionary for Eq tv. The difficulty is that we can never know which instance of Eq to use because we never get any more information about tv. - + + +Note +that the reachability condition is weaker than saying that a is +functionally dependendent on a type variable free in +type (see ). The reason for this is there +might be a "hidden" dependency, in a superclass perhaps. So +"reachable" is a conservative approximation to "functionally dependent". +For example, consider: + + class C a b | a -> b where ... + class C a b => D a b where ... + f :: forall a b. D a b => a -> a + +This is fine, because in fact a does functionally determine b +but that is not immediately apparent from f's type.