@@ -234,9 +234,6 @@ actuallyUnify context@(Context _ _ firstDesc _ secondDesc) =
234 Var Rigid maybeSuper maybeName ->
234 Var Rigid maybeSuper maybeName ->
235 unifyRigid context maybeSuper maybeName firstContent secondContent
235 unifyRigid context maybeSuper maybeName firstContent secondContent
238− unifyAtom context name secondContent
240 Alias name args realVar ->
237 Alias name args realVar ->
241 unifyAlias context name args realVar secondContent
238 unifyAlias context name args realVar secondContent
@@ -260,9 +257,6 @@ unifyFlex context otherContent =
260 Var Rigid _ _ ->
257 Var Rigid _ _ ->
261 merge context otherContent
258 merge context otherContent
264− merge context otherContent
266 Alias _ _ _ ->
260 Alias _ _ _ ->
267 merge context otherContent
261 merge context otherContent
@@ -298,9 +292,6 @@ unifyRigid context maybeSuper maybeName content otherContent =
298 mismatch context $ Just $
292 mismatch context $ Just $
299 doubleBad (Error.Rigid maybeName) (Error.Rigid otherMaybeName)
293 doubleBad (Error.Rigid maybeName) (Error.Rigid otherMaybeName)
302− mismatch context (Just (badRigid maybeName))
304 Alias _ _ _ ->
295 Alias _ _ _ ->
305 mismatch context (Just (badRigid maybeName))
296 mismatch context (Just (badRigid maybeName))
@@ -318,12 +309,6 @@ unifyFlexSuper context super content otherContent =
318 Structure term ->
309 Structure term ->
319 unifyFlexSuperStructure context super term
310 unifyFlexSuperStructure context super term
322− if atomMatchesSuper super name then
323− merge context otherContent
325− mismatch context (Just (badSuper super))
327 Var Rigid Nothing maybeName ->
312 Var Rigid Nothing maybeName ->
328 mismatch context (Just (doubleBad (errorSuper super) (Error.Rigid maybeName)))
313 mismatch context (Just (doubleBad (errorSuper super) (Error.Rigid maybeName)))
@@ -379,71 +364,71 @@ combineRigidSupers rigid flex =
379 || (rigid == CompAppend && (flex == Comparable || flex == Appendable))
364 || (rigid == CompAppend && (flex == Comparable || flex == Appendable))
382−isPrimitiveFrom :: [Text] -> Var.Canonical -> Bool
383−isPrimitiveFrom prims var =
384− any (\p -> Var.isPrim p var) prims
387atomMatchesSuper :: Super -> Var.Canonical -> Bool
367atomMatchesSuper :: Super -> Var.Canonical -> Bool
388atomMatchesSuper super name =
368atomMatchesSuper super name =
389 case super of
369 case super of
390 Number ->
370 Number ->
391− isPrimitiveFrom ["Int", "Float"] name
371+ elem name [ Var.int, Var.float ]
393 Comparable ->
373 Comparable ->
394− isPrimitiveFrom ["Int", "Float", "Char", "String"] name
374+ elem name [ Var.string, Var.int, Var.float, Var.char]
396 Appendable ->
376 Appendable ->
397− Var.isPrim "String" name
377+ name == Var.string
399 CompAppend ->
379 CompAppend ->
400− Var.isPrim "String" name
380+ name == Var.string
403unifyFlexSuperStructure :: Context -> Super -> FlatType -> Unify ()
383unifyFlexSuperStructure :: Context -> Super -> FlatType -> Unify ()
404unifyFlexSuperStructure context super term =
384unifyFlexSuperStructure context super term =
405− do appStructure <- liftIO (collectApps term)
406− case appStructure of
385+ do case term of
407− Other ->
386+ App1 name [] ->
387+ if atomMatchesSuper super name then
388+ merge context (Structure term)
408 mismatch context (Just (badSuper super))
390 mismatch context (Just (badSuper super))
410− List variable ->
392+ App1 name [variable] | name == Var.list ->
411− case super of
393+ case super of
412− Number ->
394+ Number ->
413− mismatch context (Just (badSuper super))
395+ mismatch context (Just (badSuper super))
415− Appendable ->
397+ Appendable ->
416− merge context (Structure term)
398+ merge context (Structure term)
418− Comparable ->
400+ Comparable ->
419− do comparableOccursCheck context
401+ do comparableOccursCheck context
420− merge context (Structure term)
402+ merge context (Structure term)
421− unifyComparableRecursive (_orientation context) variable
403+ unifyComparableRecursive (_orientation context) variable
423− CompAppend ->
405+ CompAppend ->
424− do comparableOccursCheck context
406+ do comparableOccursCheck context
425− merge context (Structure term)
407+ merge context (Structure term)
426− unifyComparableRecursive (_orientation context) variable
408+ unifyComparableRecursive (_orientation context) variable
428− Tuple entries ->
410+ App1 name args | Var.isTuple name ->
429− case super of
411+ case super of
430− Number ->
412+ Number ->
431− mismatch context (Just (badSuper super))
413+ mismatch context (Just (badSuper super))
433− Appendable ->
415+ Appendable ->
434− mismatch context (Just (badSuper super))
416+ mismatch context (Just (badSuper super))
436− Comparable ->
418+ Comparable ->
437− if length entries > 6 then
419+ if length args > 6 then
438− mismatch context (Just (Error.TooLongComparableTuple (length entries)))
420+ mismatch context (Just (Error.TooLongComparableTuple (length args)))
441− do comparableOccursCheck context
423+ do comparableOccursCheck context
442− merge context (Structure term)
424+ merge context (Structure term)
443− mapM_ (unifyComparableRecursive (_orientation context)) entries
425+ mapM_ (unifyComparableRecursive (_orientation context)) args
445− CompAppend ->
427+ CompAppend ->
428+ mismatch context (Just (badSuper super))
446− mismatch context (Just (badSuper super))
431+ mismatch context (Just (badSuper super))
449-- TODO: is there some way to avoid doing this?
434-- TODO: is there some way to avoid doing this?
@@ -472,38 +457,6 @@ unifyComparableRecursive orientation var =
472 guardedUnify orientation compVar var
457 guardedUnify orientation compVar var
481−collectApps :: FlatType -> IO AppStructure
485− collectAppsHelp [arg] =<< getContent func
491−collectAppsHelp :: [Variable] -> Content -> IO AppStructure
492−collectAppsHelp args content =
493− case (content, args) of
494− (Structure (App1 func arg), _) ->
495− collectAppsHelp (arg : args) =<< getContent func
497− (Atom name, [arg]) | Var.isList name ->
500− (Atom name, _) | Var.isTuple name ->
501− return (Tuple (reverse args))
507collectArgs :: Variable -> IO [Variable]
460collectArgs :: Variable -> IO [Variable]
508collectArgs variable =
461collectArgs variable =
509 collectArgsHelp [] variable
462 collectArgsHelp [] variable
@@ -526,52 +479,6 @@ getContent variable =
532−unifyAtom :: Context -> Var.Canonical -> Content -> Unify ()
533−unifyAtom context name otherContent =
534− case otherContent of
538− Var Flex Nothing _ ->
539− merge context (Atom name)
541− Var Flex (Just super) _ ->
542− if atomMatchesSuper super name then
543− merge context (Atom name)
546− mismatch context (Just ((Error.flipReason (badSuper super))))
548− Var Rigid _ maybeName ->
549− mismatch context (Just (Error.flipReason (badRigid maybeName)))
552− if name == otherName then
553− merge context otherContent
557− if isIntFloat name otherName || isIntFloat otherName name then
562− Alias _ _ realVar ->
563− subUnify context (_first context) realVar
566− mismatch context Nothing
569−isIntFloat :: Var.Canonical -> Var.Canonical -> Bool
570−isIntFloat name otherName =
571− Var.isPrim "Int" name && Var.isPrim "Float" otherName
575-- UNIFY ALIASES
482-- UNIFY ALIASES
@@ -587,9 +494,6 @@ unifyAlias context name args realVar otherContent =
587 Var _ _ _ ->
494 Var _ _ _ ->
588 subUnify context realVar (_second context)
495 subUnify context realVar (_second context)
591− subUnify context realVar (_second context)
593 Alias otherName otherArgs otherRealVar ->
497 Alias otherName otherArgs otherRealVar ->
594 if name == otherName then
498 if name == otherName then
595 do zipWithM_ (subUnify context) (map snd args) (map snd otherArgs)
499 do zipWithM_ (subUnify context) (map snd args) (map snd otherArgs)
@@ -621,18 +525,21 @@ unifyStructure context term content otherContent =
621 Var Rigid _ maybeName ->
525 Var Rigid _ maybeName ->
622 mismatch context (Just (Error.flipReason (badRigid maybeName)))
526 mismatch context (Just (Error.flipReason (badRigid maybeName)))
625− mismatch context Nothing
627 Alias _ _ realVar ->
528 Alias _ _ realVar ->
628 subUnify context (_first context) realVar
529 subUnify context (_first context) realVar
630 Structure otherTerm ->
531 Structure otherTerm ->
631 case (term, otherTerm) of
532 case (term, otherTerm) of
632− (App1 func arg, App1 otherFunc otherArg) ->
533+ (App1 name args, App1 otherName otherArgs) ->
633− do subUnify context func otherFunc
534+ if name == otherName then
634− subUnify context arg otherArg
535+ do zipWithM_ (subUnify context) args otherArgs
635− merge context otherContent
536+ merge context otherContent
538+ else if isIntFloat name otherName || isIntFloat otherName name then
539+ mismatch context (Just Error.IntFloat)
542+ mismatch context Nothing
637 (Fun1 arg result, Fun1 otherArg otherResult) ->
544 (Fun1 arg result, Fun1 otherArg otherResult) ->
638 do subUnify context arg otherArg
545 do subUnify context arg otherArg
@@ -657,6 +564,11 @@ unifyStructure context term content otherContent =
657 mismatch context Nothing
564 mismatch context Nothing
567+isIntFloat :: Var.Canonical -> Var.Canonical -> Bool
568+isIntFloat name otherName =
569+ Var.isPrim "Int" name && Var.isPrim "Float" otherName
661-- UNIFY RECORDS
573-- UNIFY RECORDS