[project @ 2002-02-14 15:03:38 by simonpj]
authorsimonpj <unknown>
Thu, 14 Feb 2002 15:03:38 +0000 (15:03 +0000)
committersimonpj <unknown>
Thu, 14 Feb 2002 15:03:38 +0000 (15:03 +0000)
commit98b23d27a06eeb5e37516c3494bfd7837eabe4ba
tree73038d381adadcee84664fa694ce84adf305c80c
parent6aa2bf20adef309cbf6ff39f4989a96ef0338138
[project @ 2002-02-14 15:03:38 by simonpj]
------------------------------------
Desugar existential matches correctly
------------------------------------

Consider
data T = forall a. Ord a => T a (a->Int)

f (T x f) True  = ...expr1...
f (T y g) False = ...expr2..

When we put in the tyvars etc we get

f (T a (d::Ord a) (x::a) (f::a->Int)) True =  ...expr1...
f (T b (e::Ord a) (y::a) (g::a->Int)) True =  ...expr2...

After desugaring etc we'll get a single case:

f = \t::T b::Bool ->
    case t of
       T a (d::Ord a) (x::a) (f::a->Int)) ->
    case b of
True  -> ...expr1...
False -> ...expr2...

*** We have to substitute [a/b, d/e] in expr2! **

Originally I tried to use
(\b -> let e = d in expr2) a
to do this substitution.  While this is "correct" in a way, it fails
Lint, because e::Ord b but d::Ord a.

So now I simply do the substitution properly using substExpr.
ghc/compiler/deSugar/MatchCon.lhs