       message: "declared type is too general, " +
         if t1 is fromInferred then "#{inferred}, #{got}" else "#{got}, #{inferred}"
       conflicts: conflicts
+
+replaceQuantifiedByOrigin = (type) ->
+  if type.TypeApp
+    new TypeApp (replaceQuantifiedByOrigin type.op),
+      (replaceQuantifiedByOrigin type.arg)
+  else if type.QuantifiedVar and type.origin
+    new TypeVariable (print type.origin), star
+  else
+    type
 
 topLevelExpression = (ctx, expression) ->
   ctx.bareDefine()

    if not includesJsType currentType.type
      # Check the declared type
      declaredType = ctx.type name
      explicitType = freshInstance ctx, declaredType
      updatedDeclaredType = quantifyUnbound ctx, explicitType#(substitute ctx.substitution, explicitType)
      unify ctx, currentType.type, explicitType.type
      unifiedType = explicitType# substitute ctx.substitution, explicitType
      inferredType = quantifyUnbound ctx, unifiedType
      if not typeEq inferredType, updatedDeclaredType
        declaredTypeTooGeneral ctx, inferredType, updatedDeclaredType, declaredType
      # Context reduction
      isDeclaredConstraint = (c) ->
        entailed = entail ctx, unifiedType.constraints, c

        "(#{name}#{Array(kindArity + 1).join ' '})"
    docs: null # TODO: add docs
  available = concatMaps typeNames, ctx._scope().typeNames
  if inferredType
    if inferredType.name
      available = filterMap ((name) -> name isnt inferredType.name), available
    inferred = newMapWith 'inferred', type: printType inferredType
  else
    inferred = newMap()
