       s1 = matchType t1.types[0], t2.types[0]
       # We imply functional dependency of the form A a b c | a -> b c
       # s2 = mostGeneralUnifier (new Types (substituteList s1, t1.types[1...])), (new Types t2.types[1...])
-      s2 = unifyImpliedParams t1, t2
-      subUnion s1, s2
+      if isFailed s1
+        s1
+      else
+        unifyImpliedParams t1, t2
     else
       emptySubstitution()
   else
     unifyFail t1, t2
 
+# We need to check that the unification succeeds first before performing
+# it on the actual types
 unifyImpliedParams = (t1, t2) ->
-  mostGeneralUnifier (new Types t1.types[1...]), (new Types t2.types[1...])
+  types1 = new Types t1.types[1...]
+  types2 = new Types t2.types[1...]
+  makeSub = (types) ->
+    mapMap ((kind, name) -> new TypeVariable name, kind, {}), findFree types
+  subbed1 = substitute (makeSub types1), types1
+  subbed2 = substitute (makeSub types2), types2
+  if isFailed (sub = mostGeneralUnifier subbed1, subbed2)
+    sub
+  else
+    mostGeneralUnifier types1, types2
+
 
 # Used to convert between quantified and not quantified
 substitute = (substitution, type) ->

  inferredType = freshInstance ctx, canonicalType
  # console.log "canonicalType", canonicalType, type
  # console.log (printType canonicalType)
  # console.log (printType inferredType)
  # console.log (printType type.type)
  ctx.extendSubstitution matchType inferredType.type, type.type#(substitute ctx.substitution, type).type
  # console.log "after", (printType inferredType.type)
  reduceConstraints ctx, inferredType.constraints

      if instanceContraints
        toNormalize.push instanceContraints...
      else
        return error: instanceLookupFailed constraint
      after = subLimit ctx.substitution
      # There was a functional dependency, renormalize
