Repository : ssh://darcs.haskell.org//srv/darcs/ghc On branch : type-nats
http://hackage.haskell.org/trac/ghc/changeset/62b03d048ba69a573ea92c053d3e7cf2c1c88d93 >--------------------------------------------------------------- commit 62b03d048ba69a573ea92c053d3e7cf2c1c88d93 Author: Iavor S. Diatchki <[email protected]> Date: Sun Sep 16 15:19:56 2012 -0700 Prefer Wanteds over Derived when solving family equations: If we have a choice of a wanted and derived equation, we prefer the wanted one. To see why, consider the following example: [D] b + a ~ c [W] a + b ~ c If we use the derived one, then `c` gets defined to `b + a` and we are left with an unsolved wanted constraint because now `c` has a binding. However, if we use the wanted first, then we are left with an "unsolved" derived constraint, which is OK because derived constraints don't correspond to goals that need to be solved. (Indeed, it is likely that the derived constraint was generated by the wanted, to enable reactions where the arguments to (+) were swapped) >--------------------------------------------------------------- compiler/typecheck/TcSimplify.lhs | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-) diff --git a/compiler/typecheck/TcSimplify.lhs b/compiler/typecheck/TcSimplify.lhs index c36ee43..1d48ebc 100644 --- a/compiler/typecheck/TcSimplify.lhs +++ b/compiler/typecheck/TcSimplify.lhs @@ -1239,7 +1239,11 @@ getSolvableCTyFunEqs :: TcsUntouchables -> Cts -- Precondition: all Wanteds or Derived! -> (Cts, FunEqBinds) -- Postcondition: returns the unsolvables getSolvableCTyFunEqs untch cts - = Bag.foldlBag dflt_funeq (emptyCts, emptyFunEqBinds) cts + = let (ws,ds) = partitionBag isWantedCt cts + s1 = Bag.foldlBag dflt_funeq (emptyCts, emptyFunEqBinds) ws + in Bag.foldlBag dflt_funeq s1 ds + + where dflt_funeq :: (Cts, FunEqBinds) -> Ct -> (Cts, FunEqBinds) @@ -1290,6 +1294,19 @@ When is it ok to do so? 3) Notice that 'beta' can't be bound in ty binds already because we rewrite RHS of type family equations. See Inert Set invariants in TcInteract. + 4) If we have a choice of a wanted and derived equation, we prefer + the wanted one. To see why, consider the following example: + [D] b + a ~ c + [W] a + b ~ c + If we use the derived one, then `c` gets defined to `b + a` and we + are left with an unsolved wanted constraint because now `c` has + a binding. However, if we use the wanted first, then we are + left with an "unsolved" derived constraint, which is OK because + derived constraints don't correspond to goals that need to be solved. + (Indeed, it is likely that the derived constraint was generated + by the wanted, to enable reactions where the arguments + to (+) were swapped) + ********************************************************************************* * * _______________________________________________ Cvs-ghc mailing list [email protected] http://www.haskell.org/mailman/listinfo/cvs-ghc
