@@ -69,7 +69,7 @@ data Hint
69 | Function (Maybe Var.Canonical)
69 | Function (Maybe Var.Canonical)
70 | UnexpectedArg (Maybe Var.Canonical) Int Int Region.Region
70 | UnexpectedArg (Maybe Var.Canonical) Int Int Region.Region
71 | FunctionArity (Maybe Var.Canonical) Int Int Region.Region
71 | FunctionArity (Maybe Var.Canonical) Int Int Region.Region
72− | ReturnType String Int
72+ | ReturnType String Int Int Region.Region
73 | Instance String
73 | Instance String
74 | Literal String
74 | Literal String
75 | Pattern Pattern
75 | Pattern Pattern
@@ -306,7 +306,7 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
306 UnexpectedArg maybeName 1 1 region ->
306 UnexpectedArg maybeName 1 1 region ->
308 (Just region)
308 (Just region)
309− ("The argument to " ++ funcName maybeName ++ " is causing a mismatch.")
309+ ("The argument to " ++ funcName maybeName ++ " is causing a mismatch.")
310 ( cmpHint
310 ( cmpHint
311 (Help.capitalize (funcName maybeName) ++ " is expecting the argument to be:")
311 (Help.capitalize (funcName maybeName) ++ " is expecting the argument to be:")
312 "But it is:"
312 "But it is:"
@@ -356,37 +356,34 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
356 (text "Maybe you forgot some parentheses? Or a comma?")
356 (text "Maybe you forgot some parentheses? Or a comma?")
358 FunctionArity maybeName expected actual region ->
358 FunctionArity maybeName expected actual region ->
360− s = if expected == 1 then "" else "s"
364− ( Help.capitalize (funcName maybeName) ++ " is expecting " ++ show expected
365− ++ " argument" ++ s ++ ", but was given " ++ show actual ++ "."
367− (text "Maybe you forgot some parentheses? Or a comma?")
369− ReturnType name 0 ->
371− Nothing
360+ (Just region)
361+ ( Help.capitalize (funcName maybeName) ++ " is expecting "
362+ ++ Help.args expected ++ ", but was given " ++ show actual ++ "."
364+ (text "Maybe you forgot some parentheses? Or a comma?")
366+ ReturnType name typeArity argArity region ->
367+ if typeArity == 0 || argArity == 0 then
372− ("The type annotation for " ++ Help.functionName name ++ " does not match its definition.")
370+ ("The definition of " ++ Help.functionName name ++ " does not match its type annotation.")
373 ( cmpHint
371 ( cmpHint
374− ( "The type annotation says " ++ Help.functionName name
372+ ( "The type annotation for " ++ Help.functionName name ++ " says it is a:"
377− "But the value you defined has this type:"
374+ "But the definition (shown above) is a:"
378− []
375+ (arityHint typeArity argArity)
381− ReturnType name arity ->
378+ else
383− Nothing
380+ (Just region)
384− ("The " ++ Help.functionName name ++ " function does not match the type annotation.")
381+ ("The definition of " ++ Help.functionName name ++ " does not match its type annotation.")
385 ( cmpHint
382 ( cmpHint
386− "The definition produces values of this type:"
387− ( "But type annotation says " ++ Help.functionName name ++ " should return:"
383+ ( "The type annotation for " ++ Help.functionName name ++ " says it always returns:"
389− []
385+ "But the returned value (shown above) is a:"
386+ (arityHint typeArity argArity)
392 Instance name ->
389 Instance name ->
@@ -571,6 +568,36 @@ functionHint maybeName =
574+arityHint :: Int -> Int -> [String]
575+arityHint typeArity argArity =
576+ if typeArity == argArity then
580+ [ "The type annotation says there " ++ sayArgs typeArity
581+ ++ ", but there " ++ sayArgs argArity ++ " named in the definition."
582+ ++ " It is best practice for each argument in the type to correspond"
583+ ++ " to a named argument in the definition, so try that first!"
587+sayArgs :: Int -> String
597+ "are " ++ show n ++ " arguments"
574-- MISMATCH HELPERS
601-- MISMATCH HELPERS