I'd like to use the unification-fd
package to implement a simple typechecker for a Hindley-Milner type system. This requires the representation of polymorphic ("forall") types.
What's the best way of representing these types? The variables provided by unification-fd
, i.e. the UVar
stuff, is for unification (meta)variables, not for variables in the object language. Some possibilities I've pondered:
Add a constructor for type variables to my base functor representing types:
data TyF tcon tv a = TCon tcon [a] | TVar tv
with
zipMatch
only unifying equalTVar
s. Type instantiation consistently replaces everyUTerm (TVar a)
with afreeVar
.(Ab)use
UVar
s for type variables, and replace them withfreeVar
s when instantiating. Requires tracking of universial vs. existentialUVar
s to know which ones to replace.Leave
TVar
out ofTyF
, use separateUTerm (TyF tcon) IntVar
for monomorpic types during typechecking,UTerm (TyF tcon) tv
for polymorphic types visible from the outside, andUTerm (TyF tcon) (Either tv IntVar)
during typechecking for intermediate,let
-bound variables.
Which would be best? Is there some other way I haven't thought of?