@@ -234,9 +234,6 @@ actuallyUnify context@(Context _ _ firstDesc _ secondDesc) =
234234 Var Rigid maybeSuper maybeName ->
235235 unifyRigid context maybeSuper maybeName firstContent secondContent
236236
237− Atom name ->
238− unifyAtom context name secondContent
239−
240237 Alias name args realVar ->
241238 unifyAlias context name args realVar secondContent
242239
@@ -260,9 +257,6 @@ unifyFlex context otherContent =
260257 Var Rigid _ _ ->
261258 merge context otherContent
262259
263− Atom _ ->
264− merge context otherContent
265−
266260 Alias _ _ _ ->
267261 merge context otherContent
268262
@@ -298,9 +292,6 @@ unifyRigid context maybeSuper maybeName content otherContent =
298292 mismatch context $ Just $
299293 doubleBad (Error.Rigid maybeName) (Error.Rigid otherMaybeName)
300294
301− Atom _ ->
302− mismatch context (Just (badRigid maybeName))
303−
304295 Alias _ _ _ ->
305296 mismatch context (Just (badRigid maybeName))
306297
@@ -318,12 +309,6 @@ unifyFlexSuper context super content otherContent =
318309 Structure term ->
319310 unifyFlexSuperStructure context super term
320311
321− Atom name ->
322− if atomMatchesSuper super name then
323− merge context otherContent
324− else
325− mismatch context (Just (badSuper super))
326−
327312 Var Rigid Nothing maybeName ->
328313 mismatch context (Just (doubleBad (errorSuper super) (Error.Rigid maybeName)))
329314
@@ -379,71 +364,71 @@ combineRigidSupers rigid flex =
379364 || (rigid == CompAppend && (flex == Comparable || flex == Appendable))
380365
381366
382−isPrimitiveFrom :: [Text] -> Var.Canonical -> Bool
383−isPrimitiveFrom prims var =
384− any (\p -> Var.isPrim p var) prims
385−
386−
387367atomMatchesSuper :: Super -> Var.Canonical -> Bool
388368atomMatchesSuper super name =
389369 case super of
390370 Number ->
391− isPrimitiveFrom ["Int", "Float"] name
371+ elem name [ Var.int, Var.float ]
392372
393373 Comparable ->
394− isPrimitiveFrom ["Int", "Float", "Char", "String"] name
374+ elem name [ Var.string, Var.int, Var.float, Var.char]
395375
396376 Appendable ->
397− Var.isPrim "String" name
377+ name == Var.string
398378
399379 CompAppend ->
400− Var.isPrim "String" name
380+ name == Var.string
401381
402382
403383unifyFlexSuperStructure :: Context -> Super -> FlatType -> Unify ()
404384unifyFlexSuperStructure context super term =
405− do appStructure <- liftIO (collectApps term)
406− case appStructure of
407− Other ->
385+ do case term of
386+ App1 name [] ->
387+ if atomMatchesSuper super name then
388+ merge context (Structure term)
389+ else
408390 mismatch context (Just (badSuper super))
409391
410− List variable ->
411− case super of
412− Number ->
413− mismatch context (Just (badSuper super))
392+ App1 name [variable] | name == Var.list ->
393+ case super of
394+ Number ->
395+ mismatch context (Just (badSuper super))
414396
415− Appendable ->
416− merge context (Structure term)
397+ Appendable ->
398+ merge context (Structure term)
417399
418− Comparable ->
419− do comparableOccursCheck context
420− merge context (Structure term)
421− unifyComparableRecursive (_orientation context) variable
400+ Comparable ->
401+ do comparableOccursCheck context
402+ merge context (Structure term)
403+ unifyComparableRecursive (_orientation context) variable
422404
423− CompAppend ->
424− do comparableOccursCheck context
425− merge context (Structure term)
426− unifyComparableRecursive (_orientation context) variable
405+ CompAppend ->
406+ do comparableOccursCheck context
407+ merge context (Structure term)
408+ unifyComparableRecursive (_orientation context) variable
427409
428− Tuple entries ->
429− case super of
430− Number ->
431− mismatch context (Just (badSuper super))
410+ App1 name args | Var.isTuple name ->
411+ case super of
412+ Number ->
413+ mismatch context (Just (badSuper super))
432414
433− Appendable ->
434− mismatch context (Just (badSuper super))
415+ Appendable ->
416+ mismatch context (Just (badSuper super))
435417
436− Comparable ->
437− if length entries > 6 then
438− mismatch context (Just (Error.TooLongComparableTuple (length entries)))
418+ Comparable ->
419+ if length args > 6 then
420+ mismatch context (Just (Error.TooLongComparableTuple (length args)))
439421
440− else
441− do comparableOccursCheck context
442− merge context (Structure term)
443− mapM_ (unifyComparableRecursive (_orientation context)) entries
422+ else
423+ do comparableOccursCheck context
424+ merge context (Structure term)
425+ mapM_ (unifyComparableRecursive (_orientation context)) args
444426
445− CompAppend ->
446− mismatch context (Just (badSuper super))
427+ CompAppend ->
428+ mismatch context (Just (badSuper super))
429+
430+ _ ->
431+ mismatch context (Just (badSuper super))
447432
448433
449434-- TODO: is there some way to avoid doing this?
@@ -472,38 +457,6 @@ unifyComparableRecursive orientation var =
472457 guardedUnify orientation compVar var
473458
474459
475−data AppStructure
476− = List Variable
477− | Tuple [Variable]
478− | Other
479−
480−
481−collectApps :: FlatType -> IO AppStructure
482−collectApps term =
483− case term of
484− App1 func arg ->
485− collectAppsHelp [arg] =<< getContent func
486−
487− _ ->
488− return Other
489−
490−
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
496−
497− (Atom name, [arg]) | Var.isList name ->
498− return (List arg)
499−
500− (Atom name, _) | Var.isTuple name ->
501− return (Tuple (reverse args))
502−
503− _ ->
504− return Other
505−
506−
507460collectArgs :: Variable -> IO [Variable]
508461collectArgs variable =
509462 collectArgsHelp [] variable
@@ -526,52 +479,6 @@ getContent variable =
526479
527480
528481
529−-- UNIFY ATOMS
530−
531−
532−unifyAtom :: Context -> Var.Canonical -> Content -> Unify ()
533−unifyAtom context name otherContent =
534− case otherContent of
535− Error _ ->
536− return ()
537−
538− Var Flex Nothing _ ->
539− merge context (Atom name)
540−
541− Var Flex (Just super) _ ->
542− if atomMatchesSuper super name then
543− merge context (Atom name)
544−
545− else
546− mismatch context (Just ((Error.flipReason (badSuper super))))
547−
548− Var Rigid _ maybeName ->
549− mismatch context (Just (Error.flipReason (badRigid maybeName)))
550−
551− Atom otherName ->
552− if name == otherName then
553− merge context otherContent
554−
555− else
556− mismatch context $
557− if isIntFloat name otherName || isIntFloat otherName name then
558− Just Error.IntFloat
559− else
560− Nothing
561−
562− Alias _ _ realVar ->
563− subUnify context (_first context) realVar
564−
565− Structure _ ->
566− mismatch context Nothing
567−
568−
569−isIntFloat :: Var.Canonical -> Var.Canonical -> Bool
570−isIntFloat name otherName =
571− Var.isPrim "Int" name && Var.isPrim "Float" otherName
572−
573−
574−
575482-- UNIFY ALIASES
576483
577484
@@ -587,9 +494,6 @@ unifyAlias context name args realVar otherContent =
587494 Var _ _ _ ->
588495 subUnify context realVar (_second context)
589496
590− Atom _ ->
591− subUnify context realVar (_second context)
592−
593497 Alias otherName otherArgs otherRealVar ->
594498 if name == otherName then
595499 do zipWithM_ (subUnify context) (map snd args) (map snd otherArgs)
@@ -621,18 +525,21 @@ unifyStructure context term content otherContent =
621525 Var Rigid _ maybeName ->
622526 mismatch context (Just (Error.flipReason (badRigid maybeName)))
623527
624− Atom _ ->
625− mismatch context Nothing
626−
627528 Alias _ _ realVar ->
628529 subUnify context (_first context) realVar
629530
630531 Structure otherTerm ->
631532 case (term, otherTerm) of
632− (App1 func arg, App1 otherFunc otherArg) ->
633− do subUnify context func otherFunc
634− subUnify context arg otherArg
635− merge context otherContent
533+ (App1 name args, App1 otherName otherArgs) ->
534+ if name == otherName then
535+ do zipWithM_ (subUnify context) args otherArgs
536+ merge context otherContent
537+
538+ else if isIntFloat name otherName || isIntFloat otherName name then
539+ mismatch context (Just Error.IntFloat)
540+
541+ else
542+ mismatch context Nothing
636543
637544 (Fun1 arg result, Fun1 otherArg otherResult) ->
638545 do subUnify context arg otherArg
@@ -657,6 +564,11 @@ unifyStructure context term content otherContent =
657564 mismatch context Nothing
658565
659566
567+isIntFloat :: Var.Canonical -> Var.Canonical -> Bool
568+isIntFloat name otherName =
569+ Var.isPrim "Int" name && Var.isPrim "Float" otherName
570+
571+
660572
661573-- UNIFY RECORDS
662574