@@ -42,13 +42,13 @@ type Unify =
4242
4343
4444newtype RawMismatch =
45− RawMismatch (AstType.Canonical, AstType.Canonical, Error.Note)
45+ RawMismatch (AstType.Canonical, AstType.Canonical, Maybe String)
4646
4747
4848typeError
4949 :: UF.Point Descriptor
5050 -> UF.Point Descriptor
51− -> Error.Note
51+ -> Maybe String
5252 -> Unify a
5353typeError leftType rightType note =
5454 do leftSrcType <- liftIO (toSrcType leftType)
@@ -121,15 +121,15 @@ actuallyUnify variable1 variable2 = do
121121 Var.BuiltIn | name `elem` ["Int","Float"] -> flexAndUnify svar
122122 Var.Local | List.isPrefixOf "number" name -> flexAndUnify svar
123123 _ ->
124− typeError variable1 variable2 Error.NoNote
124+ typeError variable1 variable2 Nothing
125125
126126 comparableError maybeHint =
127− typeError variable1 variable2 $ Error.PostNote $
127+ typeError variable1 variable2 $ Just $
128128 "Note: comparable types include Int, Float, Char, String, lists, and tuples."
129129 ++ maybe "" ("\n"++) maybeHint
130130
131131 appendableError =
132− typeError variable1 variable2 $ Error.PostNote $
132+ typeError variable1 variable2 $ Just $
133133 "Note: appendable types include only Strings, Lists, and Text."
134134
135135 unifyComparable v (Var.Canonical home name) =
@@ -164,12 +164,8 @@ actuallyUnify variable1 variable2 = do
164164 _ -> appendableError
165165
166166 rigidError var =
167− let v = render (pretty Never var)
168− in
169− typeError variable1 variable2 $ Error.PreNote $
170− "Could not unify rigid type variable `" ++ v ++ "`. The problem probably\n"
171− ++ "relates to the type variable being shared between two type annotations.\n"
172− ++ "Try commenting out some type annotations and see what happens."
167+ typeError variable1 variable2 $ Just $
168+ rigidErrorMessage (render (pretty Never var))
173169
174170 superUnify =
175171 case (flex desc1, flex desc2, name desc1, name desc2) of
@@ -195,7 +191,7 @@ actuallyUnify variable1 variable2 = do
195191
196192 (Rigid, _, _, _) -> rigidError variable1
197193 (_, Rigid, _, _) -> rigidError variable2
198− _ -> typeError variable1 variable2 Error.NoNote
194+ _ -> typeError variable1 variable2 Nothing
199195
200196 case (structure desc1, structure desc2) of
201197 (Nothing, Nothing) | flex desc1 == Flexible && flex desc1 == Flexible ->
@@ -239,7 +235,19 @@ actuallyUnify variable1 variable2 = do
239235 (Record1 _ _, Record1 _ _) ->
240236 recordUnify fresh variable1 variable2
241237
242− _ -> typeError variable1 variable2 Error.NoNote
238+ _ -> typeError variable1 variable2 Nothing
239+
240+
241+-- RIGID ERROR
242+
243+rigidErrorMessage :: String -> String
244+rigidErrorMessage var =
245+ "Could not unify user provided type variable `" ++ var ++ "`. The most likely cases are:\n\n"
246+ ++ " 1. The type you wrote down is too general. It says any type can go through\n"
247+ ++ " but in fact only a certain type can.\n"
248+ ++ " 2. A type variable is probably being shared between two type annotations.\n"
249+ ++ " They are treated as different things in the current implementation, so\n"
250+ ++ " Try commenting out some type annotations and see what happens."
243251
244252
245253-- RECORD UNIFICATION
@@ -262,14 +270,14 @@ recordUnify fresh variable1 variable2 =
262270 let uniqueFields2 = diffFields fields2 fields1
263271
264272 let addFieldMismatchError missingFields =
265− typeError variable1 variable2 $ Error.PreNote $
273+ typeError variable1 variable2 $ Just $
266274 fieldMismatchError missingFields
267275
268276 case (ext1, ext2) of
269277 (Empty _, Empty _) ->
270278 case Map.null uniqueFields1 && Map.null uniqueFields2 of
271279 True -> return ()
272− False -> typeError variable1 variable2 Error.NoNote
280+ False -> typeError variable1 variable2 Nothing
273281
274282 (Empty var1, Extension var2) ->
275283 case (Map.null uniqueFields1, Map.null uniqueFields2) of