   mapped.start = (subStart sub)
   mapped.fails = sub.fails
   for name in [(subStart sub)...(subLimit sub)] by 1 when v = (inSub sub, name)
-    mapped.vars[name] = fn v
+    setInSub mapped, name, fn v
   mapped
 
 subIntersection = (subA, subB) ->

  polymorphicVars = filterMap ((name) -> inSet vars, name), findFree type
  kinds = mapToArray polymorphicVars
  varIndex = 0
  quantifiedVars = mapToSubstitution mapMap (-> new QuantifiedVar varIndex++), polymorphicVars
  new ForAll kinds, (substitute quantifiedVars, type)

star = '*'

# Unlike in Jones, we simply use substitute for both variables and quantifieds
# - variables are strings, wheres quantifieds are ints
substitute = (substitution, type) ->
  if type.TypeVariable
    substitution.vars and (inSub substitution, type.name) or
      substitution.values and (lookupInMap substitution, type.name) or type
  else if type.QuantifiedVar
    substitution[type.var] or type
  else if type.TypeApp
