on master help sign in
Optimize case in combineFlexSupers to fail in fewer steps
7a6d5a4Evan Czaplicki
src/Type/Unify.hs+30−21
@@ -315,12 +315,13 @@ unifySuper context super otherContent =
315
315
316 Var Flex (Just otherSuper) _ ->
316 Var Flex (Just otherSuper) _ ->
317 case combineFlexSupers super otherSuper of
317 case combineFlexSupers super otherSuper of
318− Left reason ->
319− mismatch context (Just reason)
320−
321− Right newSuper ->
318+ Just newSuper ->
322 merge context (Var Flex (Just newSuper) Nothing)
319 merge context (Var Flex (Just newSuper) Nothing)
323
320
321+ Nothing ->
322+ mismatch context $ Just $
323+ doubleBad (errorSuper super) (errorSuper otherSuper)
324+
324 Alias _ _ realVar ->
325 Alias _ _ realVar ->
325 subUnify context (_first context) realVar
326 subUnify context (_first context) realVar
326
327
@@ -328,27 +329,35 @@ unifySuper context super otherContent =
328 return ()
329 return ()
329
330
330
331
331−combineFlexSupers :: Super -> Super -> Either Error.Reason Super
332+combineFlexSupers :: Super -> Super -> Maybe Super
332combineFlexSupers firstSuper secondSuper =
333combineFlexSupers firstSuper secondSuper =
333− case (firstSuper, secondSuper) of
334+ case firstSuper of
334− (Number , Number ) -> Right Number
335+ Number ->
335− (Comparable, Number ) -> Right Number
336+ case secondSuper of
336− (Number , Comparable) -> Right Number
337+ Number -> Just firstSuper
337−
338+ Comparable -> Just firstSuper
338− (Comparable, Comparable) -> Right Comparable
339+ _ -> Nothing
339− (Appendable, Appendable) -> Right Appendable
340
340
341− (Appendable, Comparable) -> Right CompAppend
341+ Comparable ->
342+ case secondSuper of
343+ Comparable -> Just secondSuper
344+ Number -> Just secondSuper
342− (Comparable, Appendable) -> Right CompAppend
345+ Appendable -> Just CompAppend
346+ CompAppend -> Just secondSuper
343
347
344− (CompAppend, CompAppend) -> Right CompAppend
348+ Appendable ->
349+ case secondSuper of
345− (CompAppend, Comparable) -> Right CompAppend
350+ Comparable -> Just CompAppend
346− (Comparable, CompAppend) -> Right CompAppend
351+ Appendable -> Just secondSuper
347− (CompAppend, Appendable) -> Right CompAppend
352+ CompAppend -> Just secondSuper
348− (Appendable, CompAppend) -> Right CompAppend
353+ Number -> Nothing
349
354
350− (_ , _ ) ->
355+ CompAppend ->
351− Left $ doubleBad (errorSuper firstSuper) (errorSuper secondSuper)
356+ case secondSuper of
357+ Comparable -> Just firstSuper
358+ Appendable -> Just firstSuper
359+ CompAppend -> Just firstSuper
360+ Number -> Nothing
352
361
353
362
354combineRigidSupers :: Super -> Super -> Bool
363combineRigidSupers :: Super -> Super -> Bool