   catch e
     return "#{type}"
 
+prettyPrint = (type) ->
+  if type.ForAll
+    prettyPrint type.type
+  else if type.Constrained
+    if _notEmpty type.constraints
+      (map printType, join [type.type], type.constraints).join ' '
+    else
+      printType type.type
+
 printType = (type) ->
-  if type instanceof TypeVariable
+  if type.TypeVariable
     "#{type.name}"
-  else if type instanceof QuantifiedVar
+  else if type.QuantifiedVar
     "#{type.var}"
-  else if type instanceof TypeConstr
+  else if type.TypeConstr
     "#{type.name}"
-  else if type instanceof TypeApp
+  else if type.TypeApp
     flattenType collectArgs type
-  else if type instanceof ForAll
+  else if type.ForAll
     "(∀ #{printType type.type})"
-  else if type instanceof ClassConstraint
+  else if type.ClassConstraint
     "(#{type.className} #{(map printType, type.types.types).join ' '})"
-  else if type instanceof Constrained
+  else if type.Constrained
     "(: #{(map printType, join [type.type], type.constraints).join ' '})"
-  else if type instanceof TempType
+  else if type.TempType
     "(. #{printType type.type})"
   else if Array.isArray type
     "\"#{listOf type}\""

  sub.start = name
  sub

substituionFail = (failure) ->
  sub = emptySubstitution()
  sub.fails.push failure

  {declared: {savedScopes}} = lookupCompiledModule moduleName
  {ctx} = contextWithDependencies moduleName
  {scope, type} = reference
  return [] unless scope?
  definitions = concatMaps (while scope isnt 0
    found = savedScopes[scope]
    scope = found.parent
