 
 kindsEq = (k1, k2) ->
   k1 is k2 or
+    k1 and k2 and
     k1.from and k2.from and
     (kindsEq k1.from, k2.from) and
     (kindsEq k1.to, k2.to)
+
+printKind = (kind) ->
+  if kind instanceof KindFn
+    arity = arityOfKind kind
+    "type constructor taking #{arity} argument#{if arity > 1 then 's' else ''}"
+  else
+    "type"
+
+arityOfKind = (kind) ->
+  if kind instanceof KindFn
+    1 + arityOfKind kind.arg
+  else
+    0
 
 class KindFn
   constructor: (@from, @to) ->

    # newMapWith variable.name, "occurs check failed"
  else if not kindsEq (kind variable), (kind type)
    # newMapWith variable.name, "kinds don't match for #{variable.name} and #{safePrintType type}"
    typeFail "Kinds of types don't match: ", variable, type
  else
    variable.ref.val = type
    newSubstitution()

  substitutionFail
    message: "#{message} #{(safePrintType first)}, #{(safePrintType second)}"
    conflicts: [first, second]
    # types: [t1, t2]

sortBasedOnOriginPosition = (t1, t2) ->
  if (originOf t1)?.start > (originOf t2)?.start
