Skip to content
  • Simon Peyton Jones's avatar
    [project @ 2002-02-14 15:03:38 by simonpj] · 98b23d27
    Simon Peyton Jones authored
    ------------------------------------
    	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.
    98b23d27