 
 unify = (ctx, t1, t2) ->
   throw new Error "invalid args to unify" unless ctx instanceof Context and t1 and t2
-  mostGeneralUnifier t1, t2
+  ctx.extendSubstitution mostGeneralUnifier t1, t2
 
 mostGeneralUnifier = (t1, t2) ->
   if t1.TypeVariable and t2.TypeVariable and t1.name is t2.name

    #   not isFailed mostGeneralUnifier (freshInstance ctx, def.type).type, type.type
    # [typed, notTyped] = partitionMap typesUnify, validDefinitions
    scoreAndPrint = (def) ->
      sub = mostGeneralUnifier (freshInstance ctx, def.type).type, type.type
      if isFailed sub
        score = -Infinity
      else
        score = -((subMagnitude sub) + i * 100)
      type: plainPrettyPrint def.type#score + ' ' +
      arity: def.arity
      docs: def.docs

  # allDefs = concatMaps typed, notTyped # TODO: don't use object key ordering for ordering
  # values mapMap (__ plainPrettyPrint, _type), allDefs

subMagnitude = (candidate, subject) ->
  subs = join (findSubstitutions candidate), (findSubstitutions subject)
  magnitude = 0
  for s in subs
    magnitude +=
      if s.TypeApp
        opName = actualOpName s.op
