Skip to content
  • Simon Peyton Jones's avatar
    Simplify the implementation of Implicit Parameters · 5a8ac0f8
    Simon Peyton Jones authored
    This patch re-implements implicit parameters via a class
    with a functional dependency:
    
        class IP (n::Symbol) a | n -> a where
          ip :: a
    
    This definition is in the library module GHC.IP. Notice
    how it use a type-literal, so we can have constraints like
       IP "x" Int
    Now all the functional dependency machinery works right to make
    implicit parameters behave as they should.
    
    Much special-case processing for implicit parameters can be removed
    entirely. One particularly nice thing is not having a dedicated
    "original-name cache" for implicit parameters (the nsNames field of
    NameCache).  But many other cases disappear:
    
      * BasicTypes.IPName
      * IPTyCon constructor in Tycon.TyCon
      * CIPCan constructor  in TcRnTypes.Ct
      * IPPred constructor  in Types.PredTree
    
    Implicit parameters remain special in a few ways:
    
     * Special syntax.  Eg the constraint (IP "x" Int) is parsed
       and printed as (?x::Int).  And we still have local bindings
       for implicit parameters, and occurrences thereof.
    
     * A implicit-parameter binding  (let ?x = True in e) amounts
       to a local instance declaration, which we have not had before.
       It just generates an implication contraint (easy), but when
       going under it we must purge any existing bindings for
       ?x in the inert set.  See Note [Shadowing of Implicit Parameters]
       in TcSimplify
    
     * TcMType.sizePred classifies implicit parameter constraints as size-0,
       as before the change
    
    There are accompanying patches to libraries 'base' and 'haddock'
    
    All the work was done by Iavor Diatchki
    5a8ac0f8