 subContext = (subs, context) ->
   newContext = newMap()
   for name, t of context.values
-    setInMap newContext, name, (subExp subs, t)
+    addToMap newContext, name, (subExp subs, t)
   newContext
 
 isTypeVariable = (name) ->
-  name.charCodeAt(0) >= 97
+  not (Array.isArray name) and name.charCodeAt(0) >= 97
 
 freshName = (nameIndex) ->
   # TODO: handle more than 27 variables


subPairs = (subs, pairs) ->
  for [t1, t2] in pairs
    [(subExp sub t1), (subExp sub t2)]

subExp = (subs, type) ->
  if Array.isArray type

  set.size -= 1
  delete set.values[key]

addAllToSet = (set, array) ->
  for v in array
    addToSet set, v
