@@ -42,13 +42,13 @@ type Unify =
44newtype RawMismatch =
44newtype RawMismatch =
45− RawMismatch (AstType.Canonical, AstType.Canonical, Error.Note)
45+ RawMismatch (AstType.Canonical, AstType.Canonical, Maybe String)
49 :: UF.Point Descriptor
49 :: UF.Point Descriptor
50 -> UF.Point Descriptor
50 -> UF.Point Descriptor
51− -> Error.Note
51+ -> Maybe String
52 -> Unify a
52 -> Unify a
53typeError leftType rightType note =
53typeError leftType rightType note =
54 do leftSrcType <- liftIO (toSrcType leftType)
54 do leftSrcType <- liftIO (toSrcType leftType)
@@ -121,15 +121,15 @@ actuallyUnify variable1 variable2 = do
121 Var.BuiltIn | name `elem` ["Int","Float"] -> flexAndUnify svar
121 Var.BuiltIn | name `elem` ["Int","Float"] -> flexAndUnify svar
122 Var.Local | List.isPrefixOf "number" name -> flexAndUnify svar
122 Var.Local | List.isPrefixOf "number" name -> flexAndUnify svar
124− typeError variable1 variable2 Error.NoNote
124+ typeError variable1 variable2 Nothing
126 comparableError maybeHint =
126 comparableError maybeHint =
127− typeError variable1 variable2 $ Error.PostNote $
127+ typeError variable1 variable2 $ Just $
128 "Note: comparable types include Int, Float, Char, String, lists, and tuples."
128 "Note: comparable types include Int, Float, Char, String, lists, and tuples."
129 ++ maybe "" ("\n"++) maybeHint
129 ++ maybe "" ("\n"++) maybeHint
131 appendableError =
131 appendableError =
132− typeError variable1 variable2 $ Error.PostNote $
132+ typeError variable1 variable2 $ Just $
133 "Note: appendable types include only Strings, Lists, and Text."
133 "Note: appendable types include only Strings, Lists, and Text."
135 unifyComparable v (Var.Canonical home name) =
135 unifyComparable v (Var.Canonical home name) =
@@ -164,12 +164,8 @@ actuallyUnify variable1 variable2 = do
164 _ -> appendableError
164 _ -> appendableError
166 rigidError var =
166 rigidError var =
167+ typeError variable1 variable2 $ Just $
167− let v = render (pretty Never var)
168+ rigidErrorMessage (render (pretty Never var))
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."
174 superUnify =
170 superUnify =
175 case (flex desc1, flex desc2, name desc1, name desc2) of
171 case (flex desc1, flex desc2, name desc1, name desc2) of
@@ -195,7 +191,7 @@ actuallyUnify variable1 variable2 = do
196 (Rigid, _, _, _) -> rigidError variable1
192 (Rigid, _, _, _) -> rigidError variable1
197 (_, Rigid, _, _) -> rigidError variable2
193 (_, Rigid, _, _) -> rigidError variable2
198− _ -> typeError variable1 variable2 Error.NoNote
194+ _ -> typeError variable1 variable2 Nothing
200 case (structure desc1, structure desc2) of
196 case (structure desc1, structure desc2) of
201 (Nothing, Nothing) | flex desc1 == Flexible && flex desc1 == Flexible ->
197 (Nothing, Nothing) | flex desc1 == Flexible && flex desc1 == Flexible ->
@@ -239,7 +235,19 @@ actuallyUnify variable1 variable2 = do
239 (Record1 _ _, Record1 _ _) ->
235 (Record1 _ _, Record1 _ _) ->
240 recordUnify fresh variable1 variable2
236 recordUnify fresh variable1 variable2
242− _ -> typeError variable1 variable2 Error.NoNote
238+ _ -> typeError variable1 variable2 Nothing
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."
245-- RECORD UNIFICATION
253-- RECORD UNIFICATION
@@ -262,14 +270,14 @@ recordUnify fresh variable1 variable2 =
262 let uniqueFields2 = diffFields fields2 fields1
270 let uniqueFields2 = diffFields fields2 fields1
264 let addFieldMismatchError missingFields =
272 let addFieldMismatchError missingFields =
265− typeError variable1 variable2 $ Error.PreNote $
273+ typeError variable1 variable2 $ Just $
266 fieldMismatchError missingFields
274 fieldMismatchError missingFields
268 case (ext1, ext2) of
276 case (ext1, ext2) of
269 (Empty _, Empty _) ->
277 (Empty _, Empty _) ->
270 case Map.null uniqueFields1 && Map.null uniqueFields2 of
278 case Map.null uniqueFields1 && Map.null uniqueFields2 of
271 True -> return ()
279 True -> return ()
272− False -> typeError variable1 variable2 Error.NoNote
280+ False -> typeError variable1 variable2 Nothing
274 (Empty var1, Extension var2) ->
282 (Empty var1, Extension var2) ->
275 case (Map.null uniqueFields1, Map.null uniqueFields2) of
283 case (Map.null uniqueFields1, Map.null uniqueFields2) of