From: simonpj Date: Fri, 29 Apr 2005 11:08:51 +0000 (+0000) Subject: [project @ 2005-04-29 11:08:51 by simonpj] X-Git-Tag: Initial_conversion_from_CVS_complete~638 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=f6c5ce7209e827a689bb7162f46dbf3a2736934c;p=ghc-hetmet.git [project @ 2005-04-29 11:08:51 by simonpj] Document improvements in overlap handling --- diff --git a/ghc/docs/users_guide/flags.xml b/ghc/docs/users_guide/flags.xml index 0bb4400..c4aa7cd 100644 --- a/ghc/docs/users_guide/flags.xml +++ b/ghc/docs/users_guide/flags.xml @@ -545,7 +545,8 @@ - Enable incoherent instances + Enable incoherent instances. + Implies dynamic diff --git a/ghc/docs/users_guide/glasgow_exts.xml b/ghc/docs/users_guide/glasgow_exts.xml index 3d52399..404db44 100644 --- a/ghc/docs/users_guide/glasgow_exts.xml +++ b/ghc/docs/users_guide/glasgow_exts.xml @@ -1762,7 +1762,8 @@ these declarations: instance context3 => C Int [a] where ... -- (C) instance context4 => C Int [Int] where ... -- (D) -The instances (A) and (B) match the constraint C Int Bool, but (C) and (D) do not. When matching, GHC takes +The instances (A) and (B) match the constraint C Int Bool, +but (C) and (D) do not. When matching, GHC takes no account of the context of the instance declaration (context1 etc). GHC's default behaviour is that exactly one instance must match the @@ -1795,10 +1796,33 @@ GHC will instead pick (C), without complaining about the problem of subsequent instantiations. -Because overlaps are checked and reported lazily, as described above, you need -the in the module that calls -the overloaded function, rather than in the module that defines it. - +The willingness to be overlapped or incoherent is a property of +the instance declaration itself, controlled by the +presence or otherwise of the +and flags when that mdodule is +being defined. Neither flag is required in a module that imports and uses the +instance declaration. Specifically, during the lookup process: + + +An instance declaration is ignored during the lookup process if (a) a more specific +match is found, and (b) the instance declaration was compiled with +. The flag setting for the +more-specific instance does not matter. + + +Suppose an instance declaration does not matche the constraint being looked up, but +does unify with it, so that it might match when the constraint is further +instantiated. Usually GHC will regard this as a reason for not committing to +some other constraint. But if the instance declaration was compiled with +, GHC will skip the "does-it-unify?" +check for that declaration. + + +All this makes it possible for a library author to design a library that relies on +overlapping instances without the library client having to know. + +The flag implies the + flag, but not vice versa.