@@ -3,21 +3,23 @@ module Reporting.Error.Type where
4--import Data.Aeson ((.=))
4--import Data.Aeson ((.=))
5import qualified Data.Aeson as Json
5import qualified Data.Aeson as Json
6+import qualified Text.PrettyPrint as P
7import qualified AST.Type as T
8import qualified AST.Type as T
9+import qualified Reporting.PrettyPrint as P
8import qualified Reporting.Region as R
10import qualified Reporting.Region as R
12 = Mismatch Mismatch
14 = Mismatch Mismatch
13− | InfiniteType R.Region
15+ | InfiniteType
14 | BadMain T.Canonical
16 | BadMain T.Canonical
17data Mismatch = MismatchInfo
19data Mismatch = MismatchInfo
18− { hint :: Maybe String
20+ { _hint :: Maybe String
19− , leftType :: T.Canonical
21+ , _leftType :: T.Canonical
20− , rightType :: T.Canonical
22+ , _rightType :: T.Canonical
@@ -36,3 +38,27 @@ toJson err =
36 case err of
38 case err of
37 _ -> error "Type.toJson"
39 _ -> error "Type.toJson"
44+toHint :: Error -> String
47+ Mismatch (MismatchInfo maybeHint leftType rightType) ->
48+ maybe "This expression is triggering a type mismatch." id maybeHint
50+ ++ "I am trying to infer the type, but I am getting conflicting information.\n"
51+ ++ "Some evidence suggests in has the type:\n\n"
52+ ++ P.render (P.nest 4 (P.pretty False leftType))
53+ ++ "\n\nBut other evidence suggests:\n\n"
54+ ++ P.render (P.nest 4 (P.pretty False rightType))
60+ "The 'main' value has an unsupported type:\n\n"
61+ ++ P.render (P.nest 4 (P.pretty False tipe))
63+ ++ "Please give me an Element, Html, (Signal Element), or (Signal Html) so\n"
64+ ++ "that I can render it on screen!"