     if expression.tea
       expression.tea = substitute ctx.substitution, expression.tea
     return
+  for scope in ctx.savedScopes when scope?
+    for name, def of values scope.definitions when def.type
+      def.type = substitute ctx.substitution, def.type
   return
 
 # end of API

    throw new Error "Unrecognized type in printType"

collectArgs = (type) ->
  if type instanceof TypeApp
    op = collectArgs type.op
    arg = collectArgs type.arg
    if (Array.isArray op) and (Array.isArray arg) and

  all (map isNormalizedConstraintArgument, constraint.types.types)

isNormalizedConstraintArgument = (type) ->
  if type
    if type.TypeVariable
      yes
    else if type.TypeConstr
      no
    else if type.TypeApp
      isNormalizedConstraintArgument type.op.type


typeEq = (a, b) ->
  if a.TypeVariable and b.TypeVariable or
      a.TypeConstr and b.TypeConstr
    a.name is b.name
  else if a.QuantifiedVar and b.QuantifiedVar
    a.var is b.var
  else if a.TypeApp and b.TypeApp
    (typeEq a.op, b.op) and (typeEq a.arg, b.arg)
  else if a.ForAll and b.ForAll
    typeEq a.type, b.type
  else if a.Constrained and b.Constrained
    (all zipWith typeEq, a.constraints, b.constraints) and
      (typeEq a.type, b.type)
  else if a.ClassConstraint and b.ClassConstraint
    a.className is b.className and typeEq a.types, b.types
  else if a.Types and b.Types
    all zipWith typeEq, a.types, b.types
  else
    no
