@@ -12,6 +12,7 @@ import Prelude hiding (round)
1212import Data.Monoid ((<>))
1313
1414import qualified AST.Canonical as Can
15+import qualified AST.Module.Name as ModuleName
1516import qualified AST.Utils.Type as Type
1617import qualified Data.Index as Index
1718import qualified Elm.Name as N
@@ -75,15 +76,24 @@ data Thing
7576
7677typeComparison :: Type.Localizer -> Can.Type -> Can.Type -> ( String, String, [H.Doc] ) -> H.Doc
7778typeComparison localizer actual expected ( iAmSeeing, insteadOf, soHereAreSomeThoughts ) =
79+ let
80+ (actualDoc, expectedDoc) =
81+ Type.diffToDocs localizer actual expected
82+ in
7883 H.stack $
7984 [ H.reflow iAmSeeing
80− , H.indent 4 (Type.toDoc localizer actual)
85+ , H.indent 4 actualDoc
8186 , H.reflow insteadOf
82− , H.indent 4 (Type.toDoc localizer expected)
87+ , H.indent 4 expectedDoc
8388 ]
8489 ++ soHereAreSomeThoughts
8590
8691
92+indentType :: Type.Localizer -> Can.Type -> H.Doc
93+indentType localizer tipe =
94+ H.indent 4 (H.dullyellow (Type.toDoc localizer tipe))
95+
96+
8797toDescription :: Thing -> String -> String
8898toDescription thing thatThingIs =
8999 case thing of
@@ -210,7 +220,7 @@ toMismatchReport source localizer exprRegion thing tipe expected =
210220 ,
211221 H.stack
212222 [ H.reflow $ toDescription thing "It is"
213− , Type.toDoc localizer tipe
223+ , indentType localizer tipe
214224 , H.fillSep
215225 ["But","I","only","now","how","to","negate"
216226 ,H.dullyellow "Int","and",H.dullyellow "Float","values."
@@ -234,7 +244,7 @@ toMismatchReport source localizer exprRegion thing tipe expected =
234244 ,
235245 H.stack
236246 [ H.reflow $ toDescription thing "It is"
237− , Type.toDoc localizer tipe
247+ , indentType localizer tipe
238248 , H.fillSep ["But","I","need","this","`if`","condition","to","be","a",H.dullyellow "Bool","value."]
239249 , H.toSimpleHint $
240250 "Elm does not have “truthiness” such that ints and strings and lists\
@@ -423,7 +433,7 @@ toMismatchReport source localizer exprRegion thing tipe expected =
423433 H.stack $
424434 [ H.reflow $
425435 "It is a record with this type:"
426− , Type.toDoc localizer tipe
436+ , indentType localizer tipe
427437 , H.reflow $
428438 "So maybe the ." <> N.toString field <> " field access is misspelled?"
429439 ]
@@ -457,7 +467,7 @@ toMismatchReport source localizer exprRegion thing tipe expected =
457467 H.stack
458468 [ H.reflow $
459469 "The " <> whatever <> " is not a record! It is actually a function:"
460− , Type.toDoc localizer tipe
470+ , indentType localizer tipe
461471 , H.toSimpleHint "Maybe it is missing some arguments?"
462472 ]
463473 )
@@ -470,7 +480,7 @@ toMismatchReport source localizer exprRegion thing tipe expected =
470480 H.stack
471481 [ H.reflow $
472482 "The " <> whatever <> " is not a record though! It is a:"
473− , Type.toDoc localizer tipe
483+ , indentType localizer tipe
474484 ]
475485 )
476486
@@ -493,7 +503,7 @@ toMismatchReport source localizer exprRegion thing tipe expected =
493503 H.stack
494504 [ H.reflow $
495505 "I can only update records, but this appears to be a " <> whatever <> ":"
496− , Type.toDoc localizer tipe
506+ , indentType localizer tipe
497507 ]
498508 )
499509
@@ -534,7 +544,7 @@ opLeftToDocs localizer thing op tipe expectedType =
534544 H.stack
535545 [ H.reflow $
536546 "Instead of a function, I am seeing " <> whatever <> ":"
537− , Type.toDoc localizer tipe
547+ , indentType localizer tipe
538548 , error "TODO"
539549 {-
540550 case category of
@@ -657,7 +667,7 @@ opRightToDocs localizer thing op tipe expectedType =
657667 H.stack
658668 [ H.reflow $
659669 "Instead of a function, I am seeing " <> whatever <> ":"
660− , Type.toDoc localizer tipe
670+ , indentType localizer tipe
661671 , error "TODO"
662672 {-
663673 case category of
@@ -694,22 +704,42 @@ opRightToDocs localizer thing op tipe expectedType =
694704
695705isInt :: Can.Type -> Bool
696706isInt tipe =
697− error "TODO isInt" tipe
707+ case tipe of
708+ Can.TType home name [] ->
709+ home == ModuleName.basics && name == N.int
710+
711+ _ ->
712+ False
698713
699714
700715isFloat :: Can.Type -> Bool
701716isFloat tipe =
702− error "TODO isFloat" tipe
717+ case tipe of
718+ Can.TType home name [] ->
719+ home == ModuleName.basics && name == N.float
720+
721+ _ ->
722+ False
703723
704724
705725isString :: Can.Type -> Bool
706726isString tipe =
707− error "TODO isString" tipe
727+ case tipe of
728+ Can.TType home name [] ->
729+ home == ModuleName.string && name == N.string
730+
731+ _ ->
732+ False
708733
709734
710735isList :: Can.Type -> Bool
711736isList tipe =
712− error "TODO isList" tipe
737+ case tipe of
738+ Can.TType home name [_] ->
739+ home == ModuleName.list && name == N.list
740+
741+ _ ->
742+ False
713743
714744
715745whatever :: String
@@ -786,7 +816,7 @@ badListAdd localizer direction tipe =
786816 H.stack
787817 [ H.reflow $
788818 "The " <> direction <> " side of (+) is " <> whatever <> ":"
789− , Type.toDoc localizer tipe
819+ , indentType localizer tipe
790820 , H.fillSep
791821 ["But","(+)","only","works","with",H.dullyellow "Int","and",H.dullyellow "Float","values."
792822 ]
@@ -818,7 +848,7 @@ badMath localizer operation direction op tipe otherHints =
818848 H.stack $
819849 [ H.reflow $
820850 "The " <> direction <> " side of (" <> op <> ") is a " <> whatever <> ":"
821− , Type.toDoc localizer tipe
851+ , indentType localizer tipe
822852 , H.fillSep
823853 ["But","(" <> H.text op <> ")","only","works","with"
824854 ,H.dullyellow "Int","and",H.dullyellow "Float","values."
@@ -857,7 +887,7 @@ badFDiv localizer direction tipe =
857887 ,H.dullyellow "Float" <> ","
858888 ,"but","instead","I","am","seeing:"
859889 ]
860− , Type.toDoc localizer tipe
890+ , indentType localizer tipe
861891 ]
862892 )
863893
@@ -892,7 +922,7 @@ badIDiv localizer direction tipe =
892922 ,H.dullyellow "Int" <> ","
893923 ,"but","instead","I","am","seeing:"
894924 ]
895− , Type.toDoc localizer tipe
925+ , indentType localizer tipe
896926 ]
897927 )
898928
@@ -912,7 +942,7 @@ badBool localizer op direction tipe =
912942 ["Both","sides","of","(" <> op <> ")","must","be"
913943 ,H.dullyellow "Bool","values,","but","the",direction,"side","is:"
914944 ]
915− , Type.toDoc localizer tipe
945+ , indentType localizer tipe
916946 , H.toSimpleHint
917947 "Elm does not have “truthiness” such that ints and strings and lists are\
918948 \ automatically converted to booleans. Do that conversion explicitly!"
@@ -943,7 +973,7 @@ badCompArg localizer thing op direction tipe =
943973 H.stack
944974 [ H.reflow $ toDescription thing $
945975 "The " <> direction <> " side of (" <> op <> ") is"
946− , Type.toDoc localizer tipe
976+ , indentType localizer tipe
947977 , H.fillSep
948978 ["But","(" <> H.text op <> ")","only","works","on"
949979 ,H.dullyellow "Int" <> ","