       [t2from, t2to] = t2
       unifyWith subs, [[t1from, t2from], [t1to, t2to]].concat rest
     else
-      throw new Error "Types #{t1}, #{t2} could not be unified"
+      throw new TypeError "Types #{t1}, #{t2} could not be unified", [t1, t2]
 
 subPairs = (subs, pairs) ->
   for [t1, t2] in pairs

        # TODO: replace free type variables with new unused names in function
        concreteType = lookupInMap context, expression.token
        unless concreteType
          throw new Error "Unbound variable #{expression.token}"
        [nextIndex, concreteType] = freshenFree nameIndex, concreteType
        expression.tea = concreteType
        [newMap(), nextIndex, expression]

freshName = (nameIndex) ->
  suffix = if nameIndex > 25 then nameIndex // 25 else ''
  String.fromCharCode 97 + nameIndex % 25

ignoreTypeErrors = (fn) ->
  try
    ret = fn()
  catch e
    unless e instanceof TypeError
      throw e

class TypeError extends Error
  # required for instanceof to work
  constructor: (@message, @data) -> super @message

# mycroft = (context, node, environment) ->
#   if node.label is 'numerical'
