Skip to content

Var Constructor Considered Harmful

xich edited this page Apr 30, 2013 · 3 revisions

There is a handy function:

varToCoreExpr :: Var -> CoreExpr

which always does the right thing when creating variable expressions. Depending on what the Var is, it will create: a value using the Var constructor, a type variable using (Type . TyVarTy), or a Coercion variable.

It is ok to pattern match on the Var constructor, but whenever you are building a CoreExpr, you should use varToCoreExpr.

Doing so has the nice knock-on effect that GHC's other higher-level functions Just Work. For instance, we can count on extendSubst to properly build substitution environments, rather than manually case-ing on expressions and using lower-level functions.

Clone this wiki locally