   sub.start = name
   sub
 
+isFailed = (sub) ->
+  sub.fails.length > 0
+
 substituionFail = (failure) ->
   sub = emptySubstitution()
   sub.fails.push failure

  findMatchingDefinitionsOnType type, definitions

findMatchingDefinitionsOnType = (type, definitions) ->
  setToArray definitions

# API


  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.TypeVariable
    "#{type.name}"
  else if type.QuantifiedVar
    "#{type.var}"
  else if type.TypeConstr
    "#{type.name}"
  else if type.TypeApp
    flattenType collectArgs type
  else if type.ForAll
    "(∀ #{printType type.type})"
  else if type.ClassConstraint
    "(#{type.className} #{(map printType, type.types.types).join ' '})"
  else if type.Constrained
    "(: #{(map printType, join [type.type], type.constraints).join ' '})"
  else if type.TempType
    "(. #{printType type.type})"
  else if Array.isArray type
    "\"#{listOf type}\""
