From 0f556c9933f8214240e3143e5d18b2916b540521 Mon Sep 17 00:00:00 2001 From: "simonpj@microsoft.com" Date: Thu, 9 Aug 2007 15:18:39 +0000 Subject: [PATCH] Improvd documentation for overlapping instances --- docs/users_guide/glasgow_exts.xml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml index 053c4a9..a1c25e4 100644 --- a/docs/users_guide/glasgow_exts.xml +++ b/docs/users_guide/glasgow_exts.xml @@ -2810,9 +2810,23 @@ Suppose that from the RHS of f we get the constraint GHC does not commit to instance (C), because in a particular call of f, b might be instantiate to Int, in which case instance (D) would be more specific still. -So GHC rejects the program. If you add the flag , +So GHC rejects the program. +(If you add the flag , GHC will instead pick (C), without complaining about -the problem of subsequent instantiations. +the problem of subsequent instantiations.) + +Notice that we gave a type signature to f, so GHC had to +check that f has the specified type. +Suppose instead we do not give a type signature, asking GHC to infer +it instead. In this case, GHC will refrain from +simplifying the constraint C Int [Int] (for the same reason +as before) but, rather than rejecting the program, it will infer the type + + f :: C Int b => [b] -> [b] + +That postpones the question of which instance to pick to the +call site for f +by which time more is known about the type b. The willingness to be overlapped or incoherent is a property of -- 1.7.10.4