Skip to content
  • Simon Peyton Jones's avatar
    [project @ 2002-04-01 08:23:30 by simonpj] · 9003a18c
    Simon Peyton Jones authored
    ------------------------------------
    	Change the treatment of the stupid
    	   context on data constructors
    	-----------------------------------
    
    Data types can have a context:
    
    	data (Eq a, Ord b) => T a b = T1 a b | T2 a
    
    and that makes the constructors have a context too
    (notice that T2's context is "thinned"):
    
    	T1 :: (Eq a, Ord b) => a -> b -> T a b
    	T2 :: (Eq a) => a -> T a b
    
    Furthermore, this context pops up when pattern matching
    (though GHC hasn't implemented this, but it is in H98, and
    I've fixed GHC so that it now does):
    
    	f (T2 x) = x
    gets inferred type
    	f :: Eq a => T a b -> a
    
    I say the context is "stupid" because the dictionaries passed
    are immediately discarded -- they do nothing and have no benefit.
    It's a flaw in the language.
    
    Up to now I have put this stupid context into the type of
    the "wrapper" constructors functions, T1 and T2, but that turned
    out to be jolly inconvenient for generics, and record update, and
    other functions that build values of type T (because they don't
    have suitable dictionaries available).
    
    So now I've taken the stupid context out.  I simply deal with
    it separately in the type checker on occurrences of a constructor,
    either in an expression or in a pattern.
    
    To this end
    
    * Lots of changes in DataCon, MkId
    
    * New function Inst.tcInstDataCon to instantiate a data constructor
    
    
    
    I also took the opportunity to
    
    * Rename
    	dataConId --> dataConWorkId
      for consistency.
    
    * Tidied up MkId.rebuildConArgs quite a bit, and renamed it
    	mkReboxingAlt
    
    * Add function DataCon.dataConExistentialTyVars, with the obvious meaning
    9003a18c