@@ -115,6 +115,11 @@ badSuper super =
115115 Error.BadVar (Just (errorSuper super)) Nothing
116116
117117
118+badSupers :: Super -> Super -> Error.Reason
119+badSupers super1 super2 =
120+ Error.BadVar (Just (errorSuper super1)) (Just (errorSuper super2))
121+
122+
118123doubleBad :: Error.VarType -> Error.VarType -> Error.Reason
119124doubleBad vt1 vt2 =
120125 Error.BadVar (Just vt1) (Just vt2)
@@ -206,7 +211,7 @@ actuallyUnify context@(Context _ _ firstDesc _ secondDesc) =
206211 unifyFlex context secondContent
207212
208213 Var Flex (Just super) _ ->
209− unifyFlexSuper context super secondContent
214+ unifyFlexSuper context super firstContent secondContent
210215
211216 Var Rigid maybeSuper maybeName ->
212217 unifyRigid context maybeSuper maybeName firstContent secondContent
@@ -218,7 +223,7 @@ actuallyUnify context@(Context _ _ firstDesc _ secondDesc) =
218223 unifyAlias context name args realVar secondContent
219224
220225 Structure term ->
221− unifyStructure context term secondContent
226+ unifyStructure context term firstContent secondContent
222227
223228
224229
@@ -289,8 +294,8 @@ unifyRigid context maybeSuper maybeName content otherContent =
289294-- UNIFY SUPER VARIABLES
290295
291296
292−unifyFlexSuper :: Context -> Super -> Content -> Unify ()
293−unifyFlexSuper context super otherContent =
297+unifyFlexSuper :: Context -> Super -> Content -> Content -> Unify ()
298+unifyFlexSuper context super content otherContent =
294299 case otherContent of
295300 Structure term ->
296301 unifyFlexSuperStructure context super term
@@ -311,16 +316,36 @@ unifyFlexSuper context super otherContent =
311316 mismatch context $ Just $ badRigid maybeName
312317
313318 Var Flex Nothing _ ->
314− merge context (Var Flex (Just super) Nothing)
319+ merge context content
315320
316321 Var Flex (Just otherSuper) _ ->
317− case combineFlexSupers super otherSuper of
318− Just newSuper ->
319− merge context (Var Flex (Just newSuper) Nothing)
320−
321− Nothing ->
322− mismatch context $ Just $
323− doubleBad (errorSuper super) (errorSuper otherSuper)
322+ case super of
323+ Number ->
324+ case otherSuper of
325+ Number -> merge context content
326+ Comparable -> merge context content
327+ _ -> mismatch context $ Just $ badSupers super otherSuper
328+
329+ Comparable ->
330+ case otherSuper of
331+ Comparable -> merge context otherContent
332+ Number -> merge context otherContent
333+ Appendable -> merge context (Var Flex (Just CompAppend) Nothing)
334+ CompAppend -> merge context otherContent
335+
336+ Appendable ->
337+ case otherSuper of
338+ Appendable -> merge context otherContent
339+ Comparable -> merge context (Var Flex (Just CompAppend) Nothing)
340+ CompAppend -> merge context otherContent
341+ Number -> mismatch context $ Just $ badSupers super otherSuper
342+
343+ CompAppend ->
344+ case otherSuper of
345+ Comparable -> merge context content
346+ Appendable -> merge context content
347+ CompAppend -> merge context content
348+ Number -> mismatch context $ Just $ badSupers super otherSuper
324349
325350 Alias _ _ realVar ->
326351 subUnify context (_first context) realVar
@@ -329,37 +354,6 @@ unifyFlexSuper context super otherContent =
329354 return ()
330355
331356
332−combineFlexSupers :: Super -> Super -> Maybe Super
333−combineFlexSupers firstSuper secondSuper =
334− case firstSuper of
335− Number ->
336− case secondSuper of
337− Number -> Just firstSuper
338− Comparable -> Just firstSuper
339− _ -> Nothing
340−
341− Comparable ->
342− case secondSuper of
343− Comparable -> Just secondSuper
344− Number -> Just secondSuper
345− Appendable -> Just CompAppend
346− CompAppend -> Just secondSuper
347−
348− Appendable ->
349− case secondSuper of
350− Comparable -> Just CompAppend
351− Appendable -> Just secondSuper
352− CompAppend -> Just secondSuper
353− Number -> Nothing
354−
355− CompAppend ->
356− case secondSuper of
357− Comparable -> Just firstSuper
358− Appendable -> Just firstSuper
359− CompAppend -> Just firstSuper
360− Number -> Nothing
361−
362−
363357combineRigidSupers :: Super -> Super -> Bool
364358combineRigidSupers rigid flex =
365359 rigid == flex
@@ -576,17 +570,17 @@ unifyAlias context name args realVar otherContent =
576570-- UNIFY STRUCTURES
577571
578572
579−unifyStructure :: Context -> Term1 Variable -> Content -> Unify ()
580−unifyStructure context term otherContent =
573+unifyStructure :: Context -> Term1 Variable -> Content -> Content -> Unify ()
574+unifyStructure context term content otherContent =
581575 case otherContent of
582576 Error ->
583577 return ()
584578
585579 Var Flex Nothing _ ->
586− merge context (Structure term)
580+ merge context content
587581
588582 Var Flex (Just super) _ ->
589− unifyFlexSuper (reorient context) super (Structure term)
583+ unifyFlexSuper (reorient context) super otherContent content
590584
591585 Var Rigid _ maybeName ->
592586 mismatch context (Just (Error.flipReason (badRigid maybeName)))