@@ -1,22 +1,32 @@
11{-# OPTIONS_GHC -Wall #-}
2−module Reporting.Error.Type where
2+{-# LANGUAGE OverloadedStrings #-}
3+module Reporting.Error.Type
4+ ( Error(..)
5+ , Mismatch(..), Hint(..)
6+ , Reason(..), VarType(..)
7+ , Pattern(..)
8+ , toReport
9+ , flipReason
10+ )
11+ where
312
413import Control.Arrow (first, second)
5−import qualified Data.List as List
614import qualified Data.Map as Map
715import qualified Data.Maybe as Maybe
8−import Text.PrettyPrint.ANSI.Leijen
9− ( Doc, (<>), (<+>), colon, dullyellow
10− , fillSep, indent, text, underline, vcat
11− )
16+import qualified Data.Text as Text
17+import Data.Text (Text)
1218
1319import qualified AST.Helpers as Help
1420import qualified AST.Type as Type
1521import qualified AST.Variable as Var
16−import qualified Reporting.Error.Helpers as Help
1722import qualified Reporting.Region as Region
1823import qualified Reporting.Render.Type as RenderType
1924import qualified Reporting.Report as Report
25+import qualified Reporting.Helpers as Help
26+import Reporting.Helpers
27+ ( Doc, (<>), (<+>), capitalize, colon, dullyellow, fillSep, functionName
28+ , i2t, indent, ordinalize, reflowParagraph, stack, text, underline, vcat
29+ )
2030
2131
2232
@@ -26,8 +36,8 @@ import qualified Reporting.Report as Report
2636data Error
2737 = Mismatch Mismatch
2838 | BadMain Type.Canonical
29− | BadFlags Type.Canonical (Maybe String)
30− | InfiniteType String Type.Canonical
39+ | BadFlags Type.Canonical (Maybe Text)
40+ | InfiniteType Text Type.Canonical
3141
3242
3343data Mismatch = MismatchInfo
@@ -39,8 +49,8 @@ data Mismatch = MismatchInfo
3949
4050
4151data Reason
42− = BadFields [(String, Maybe Reason)]
43− | MessyFields [String] [String] [String]
52+ = BadFields [(Text, Maybe Reason)]
53+ | MessyFields [Text] [Text] [Text]
4454 | IntFloat
4555 | TooLongComparableTuple Int
4656 | MissingArgs Int
@@ -52,7 +62,7 @@ data VarType
5262 | Comparable
5363 | Appendable
5464 | CompAppend
55− | Rigid (Maybe String)
65+ | Rigid (Maybe Text)
5666
5767
5868data Hint
@@ -70,24 +80,24 @@ data Hint
7080 | Function (Maybe Var.Canonical)
7181 | UnexpectedArg (Maybe Var.Canonical) Int Int Region.Region
7282 | FunctionArity (Maybe Var.Canonical) Int Int Region.Region
73− | ReturnType String Int Int Region.Region
74− | Instance String
75− | Literal String
83+ | ReturnType Text Int Int Region.Region
84+ | Instance Text
85+ | Literal Text
7686 | Pattern Pattern
7787 | Shader
7888 | Lambda
79− | Access (Maybe String) String
89+ | Access (Maybe Text) Text
8090 | Record
8191 -- effect manager problems
82− | Manager String
83− | State String
92+ | Manager Text
93+ | State Text
8494 | SelfMsg
8595
8696
8797data Pattern
88− = PVar String
89− | PAlias String
90− | PData String
98+ = PVar Text
99+ | PAlias Text
100+ | PCtor Var.Canonical
91101 | PRecord
92102
93103
@@ -109,8 +119,8 @@ toReport localizer err =
109119 "BAD MAIN TYPE"
110120 Nothing
111121 "The `main` value has an unsupported type."
112− ( Help.stack
113− [ Help.reflowParagraph $
122+ ( stack
123+ [ reflowParagraph $
114124 "I need Html, Svg, or a Program so I have something to render on\
115125 \ screen, but you gave me:"
116126 , indent 4 (RenderType.toDoc localizer tipe)
@@ -120,24 +130,25 @@ toReport localizer err =
120130 BadFlags tipe maybeMessage ->
121131 let
122132 context =
123− maybe "" (" the following " ++ ) maybeMessage
133+ maybe "" (" the following " <> ) maybeMessage
124134 in
125135 Report.report
126136 "BAD FLAGS"
127137 Nothing
128138 ("Your `main` is demanding an unsupported type as a flag."
129139 )
130− ( Help.stack
131− [ text ("The specific unsupported type is" ++ context ++ ":")
140+ ( stack
141+ [ text ("The specific unsupported type is" <> context <> ":")
132142 , indent 4 (RenderType.toDoc localizer tipe)
133143 , text "The types of values that can flow through in and out of Elm include:"
134− , indent 4 $ Help.reflowParagraph $
144+ , indent 4 $ reflowParagraph $
135145 "Ints, Floats, Bools, Strings, Maybes, Lists, Arrays,\
136146 \ Tuples, Json.Values, and concrete records."
137147 ]
138148 )
139149
140150
151+
141152-- TYPE MISMATCHES
142153
143154
@@ -152,18 +163,18 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
152163
153164 cmpHint leftWords rightWords extraHints =
154165 comparisonHint localizer leftType rightType leftWords rightWords
155− (typicalHints ++ map toHint extraHints)
166+ (typicalHints <> map toHint extraHints)
156167 in
157168 case hint of
158169 CaseBranch branchNumber region ->
159170 report
160171 (Just region)
161− ( "The " ++ ordinalPair branchNumber
162− ++ " branches of this `case` produce different types of values."
172+ ( "The " <> ordinalPair branchNumber
173+ <> " branches of this `case` produce different types of values."
163174 )
164175 ( cmpHint
165− ("The " ++ Help.ordinalize (branchNumber -1) ++ " branch has this type:")
166− ("But the " ++ Help.ordinalize branchNumber ++ " is:")
176+ ("The " <> ordinalize (branchNumber - 1) <> " branch has this type:")
177+ ("But the " <> ordinalize branchNumber <> " is:")
167178 [ "All branches in a `case` must have the same type. So no matter\
168179 \ which one we take, we always get back the same type of value."
169180 ]
@@ -173,7 +184,7 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
173184 report
174185 Nothing
175186 ( "All the branches of this case-expression are consistent, but the overall\n"
176− ++ "type does not match how it is used elsewhere."
187+ <> "type does not match how it is used elsewhere."
177188 )
178189 ( cmpHint
179190 "The `case` evaluates to something of type:"
@@ -208,12 +219,12 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
208219 MultiIfBranch branchNumber region ->
209220 report
210221 (Just region)
211− ( "The " ++ ordinalPair branchNumber
212− ++ " branches of this `if` produce different types of values."
222+ ( "The " <> ordinalPair branchNumber
223+ <> " branches of this `if` produce different types of values."
213224 )
214225 ( cmpHint
215− ("The " ++ Help.ordinalize (branchNumber - 1) ++ " branch has this type:")
216− ("But the "++ Help.ordinalize branchNumber ++ " is:")
226+ ("The " <> ordinalize (branchNumber - 1) <> " branch has this type:")
227+ ("But the "<> ordinalize branchNumber <> " is:")
217228 [ "All the branches of an `if` need to match so that no matter which\
218229 \ one we take, we get back the same type of value overall."
219230 ]
@@ -233,10 +244,10 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
233244 ListElement elementNumber region ->
234245 report
235246 (Just region)
236− ("The " ++ ordinalPair elementNumber ++ " entries in this list are different types of values.")
247+ ("The " <> ordinalPair elementNumber <> " entries in this list are different types of values.")
237248 ( cmpHint
238− ("The " ++ Help.ordinalize (elementNumber - 1) ++ " entry has this type:")
239− ("But the "++ Help.ordinalize elementNumber ++ " is:")
249+ ("The " <> ordinalize (elementNumber - 1) <> " entry has this type:")
250+ ("But the "<> ordinalize elementNumber <> " is:")
240251 [ "Every entry in a list needs to be the same type of value.\
241252 \ This way you never run into unexpected values partway through.\
242253 \ To mix different types in a single list, create a \"union type\" as\
@@ -247,8 +258,8 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
247258 List ->
248259 report
249260 Nothing
250− ( "All the elements in this list are the same type, but the overall\n"
251− ++ "type does not match how it is used elsewhere."
261+ ( "All the elements in this list are the same type, but the overall\
262+ \ type does not match how it is used elsewhere."
252263 )
253264 ( cmpHint
254265 "The list has type:"
@@ -259,9 +270,9 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
259270 BinopLeft op region ->
260271 report
261272 (Just region)
262− ("The left argument of " ++ prettyName op ++ " is causing a type mismatch.")
273+ ("The left argument of " <> varName op <> " is causing a type mismatch.")
263274 ( cmpHint
264− (prettyName op ++ " is expecting the left argument to be a:")
275+ (varName op <> " is expecting the left argument to be a:")
265276 "But the left argument is:"
266277 (binopHint op leftType rightType)
267278 )
@@ -269,13 +280,13 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
269280 BinopRight op region ->
270281 report
271282 (Just region)
272− ("The right side of " ++ prettyName op ++ " is causing a type mismatch.")
283+ ("The right side of " <> varName op <> " is causing a type mismatch.")
273284 ( cmpHint
274− (prettyName op ++ " is expecting the right side to be a:")
285+ (varName op <> " is expecting the right side to be a:")
275286 "But the right side is:"
276287 ( binopHint op leftType rightType
277288 ++
278− [ "With operators like " ++ prettyName op ++ " I always check the left\
289+ [ "With operators like " <> varName op <> " I always check the left\
279290 \ side first. If it seems fine, I assume it is correct and check the right\
280291 \ side. So the problem may be in how the left and right arguments interact."
281292 ]
@@ -285,7 +296,7 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
285296 Binop op ->
286297 report
287298 Nothing
288− ( "The two arguments to " ++ prettyName op ++
299+ ( "The two arguments to " <> varName op <>
289300 " are fine, but the overall type of this expression\
290301 \ does not match how it is used elsewhere."
291302 )
@@ -298,7 +309,7 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
298309 Function maybeName ->
299310 report
300311 Nothing
301− ( "The return type of " ++ funcName maybeName ++ " is being used in unexpected ways."
312+ ( "The return type of " <> maybeFuncName maybeName <> " is being used in unexpected ways."
302313 )
303314 ( cmpHint
304315 "The function results in this type of value:"
@@ -309,9 +320,9 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
309320 UnexpectedArg maybeName 1 1 region ->
310321 report
311322 (Just region)
312− ("The argument to " ++ funcName maybeName ++ " is causing a mismatch.")
323+ ("The argument to " <> maybeFuncName maybeName <> " is causing a mismatch.")
313324 ( cmpHint
314− (Help.capitalize (funcName maybeName) ++ " is expecting the argument to be:")
325+ (capitalize (maybeFuncName maybeName) <> " is expecting the argument to be:")
315326 "But it is:"
316327 (functionHint maybeName)
317328 )
@@ -319,12 +330,12 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
319330 UnexpectedArg maybeName index _totalArgs region ->
320331 report
321332 (Just region)
322− ( "The " ++ Help.ordinalize index ++ " argument to " ++ funcName maybeName
323− ++ " is causing a mismatch."
333+ ( "The " <> ordinalize index <> " argument to " <> maybeFuncName maybeName
334+ <> " is causing a mismatch."
324335 )
325336 ( cmpHint
326− ( Help.capitalize (funcName maybeName) ++ " is expecting the "
327− ++ Help.ordinalize index ++ " argument to be:"
337+ ( capitalize (maybeFuncName maybeName) <> " is expecting the "
338+ <> ordinalize index <> " argument to be:"
328339 )
329340 "But it is:"
330341 ( functionHint maybeName
@@ -335,23 +346,23 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
335346 [ "I always figure out the type of arguments from left to right. If an argument\
336347 \ is acceptable when I check it, I assume it is \"correct\" in subsequent checks.\
337348 \ So the problem may actually be in how previous arguments interact with the "
338− ++ Help.ordinalize index ++ "."
349+ <> ordinalize index <> "."
339350 ]
340351 )
341352 )
342353
343354 FunctionArity maybeName 0 actual region ->
344355 let
345− arg =
346− if actual == 1 then "an argument" else show actual ++ " arguments"
356+ args =
357+ if actual == 1 then "an argument" else i2t actual <> " arguments"
347358
348359 preHint =
349360 case maybeName of
350361 Nothing ->
351− "You are giving " ++ arg ++ " to something that is not a function!"
362+ "You are giving " <> args <> " to something that is not a function!"
352363
353364 Just name ->
354− prettyName name ++ " is not a function, but you are giving it " ++ arg ++ "!"
365+ varName name <> " is not a function, but you are giving it " <> args <> "!"
355366 in
356367 report
357368 (Just region)
@@ -361,8 +372,8 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
361372 FunctionArity maybeName expected actual region ->
362373 report
363374 (Just region)
364− ( Help.capitalize (funcName maybeName) ++ " is expecting "
365− ++ Help.args expected ++ ", but was given " ++ show actual ++ "."
375+ ( capitalize (maybeFuncName maybeName) <> " is expecting "
376+ <> Help.args expected <> ", but was given " <> i2t actual <> "."
366377 )
367378 (text "Maybe you forgot some parentheses? Or a comma?")
368379
@@ -370,9 +381,9 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
370381 if typeArity == 0 || argArity == 0 then
371382 report
372383 (Just region)
373− ("The definition of " ++ Help.functionName name ++ " does not match its type annotation.")
384+ ("The definition of " <> functionName name <> " does not match its type annotation.")
374385 ( cmpHint
375− ( "The type annotation for " ++ Help.functionName name ++ " says it is a:"
386+ ( "The type annotation for " <> functionName name <> " says it is a:"
376387 )
377388 "But the definition (shown above) is a:"
378389 (arityHint typeArity argArity)
@@ -381,20 +392,24 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
381392 else
382393 report
383394 (Just region)
384− ("The definition of " ++ Help.functionName name ++ " does not match its type annotation.")
395+ ("The definition of " <> functionName name <> " does not match its type annotation.")
385396 ( cmpHint
386− ( "The type annotation for " ++ Help.functionName name ++ " says it always returns:"
397+ ( "The type annotation for " <> functionName name <> " says it always returns:"
387398 )
388399 "But the returned value (shown above) is a:"
389400 (arityHint typeArity argArity)
390401 )
391402
392− Instance name ->
403+ Instance var ->
404+ let
405+ name =
406+ functionName var
407+ in
393408 report
394409 Nothing
395− (Help.functionName name ++ " is being used in an unexpected way.")
410+ (name <> " is being used in an unexpected way.")
396411 ( cmpHint
397− ("Based on its definition, " ++ Help.functionName name ++ " has this type:")
412+ ("Based on its definition, " <> name <> " has this type:")
398413 "But you are trying to use it as:"
399414 []
400415 )
@@ -402,10 +417,10 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
402417 Literal name ->
403418 report
404419 Nothing
405− ( "This " ++ name ++ " value is being used as if it is some other type of value."
420+ ( "This " <> name <> " value is being used as if it is some other type of value."
406421 )
407422 ( cmpHint
408− ("The " ++ name ++ " definitely has this type:")
423+ ("The " <> name <> " definitely has this type:")
409424 ("But it is being used as:")
410425 []
411426 )
@@ -414,15 +429,24 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
414429 let
415430 thing =
416431 case patErr of
417− PVar name -> "variable `" ++ name ++ "`"
418− PAlias name -> "alias `" ++ name ++ "`"
419− PRecord -> "this record"
420− PData name ->
421− if Help.isTuple name then "this tuple" else "tag `" ++ name ++ "`"
432+ PVar name ->
433+ "variable `" <> name <> "`"
434+
435+ PAlias name ->
436+ "alias `" <> name <> "`"
437+
438+ PRecord ->
439+ "this record"
440+
441+ PCtor (Var.Canonical Var.BuiltIn name) | Help.isTuple name ->
442+ "this tuple"
443+
444+ PCtor name ->
445+ "tag `" <> Var.toText name <> "`"
422446 in
423447 report
424448 Nothing
425− ( Help.capitalize thing ++ " is causing problems in this pattern match."
449+ ( capitalize thing <> " is causing problems in this pattern match."
426450 )
427451 ( cmpHint
428452 "The pattern matches things of type:"
@@ -452,25 +476,23 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
452476
453477 Access (Just body) field ->
454478 let
455− header =
456− "`" ++ body ++ "` does not have a field named `" ++ field ++ "`."
479+ header = "`" <> body <> "` does not have a field named `" <> field <> "`."
457480 in
458− report Nothing header $ Help.stack $
459− [ Help.reflowParagraph $ "The type of `" ++ body ++ "` is:"
481+ report Nothing header $ stack $
482+ [ reflowParagraph $ "The type of `" <> body <> "` is:"
460483 , indent 4 $ dullyellow $ RenderType.toDoc localizer leftType
461− , Help.reflowParagraph $ "Which does not contain a field named `" ++ field ++ "`."
484+ , reflowParagraph $ "Which does not contain a field named `" <> field <> "`."
462485 ]
463486 ++ typicalHints
464487
465488 Access Nothing field ->
466489 let
467− header =
468− "Cannot access a field named `" ++ field ++ "`."
490+ header = "Cannot access a field named `" <> field <> "`."
469491 in
470− report Nothing header $ Help.stack $
471− [ Help.reflowParagraph $ "You are trying to get `" ++ field ++ "` from a value with this type:"
492+ report Nothing header $ stack $
493+ [ reflowParagraph $ "You are trying to get `" <> field <> "` from a value with this type:"
472494 , indent 4 $ dullyellow $ RenderType.toDoc localizer leftType
473− , Help.reflowParagraph $ "It is not in there!"
495+ , reflowParagraph $ "It is not in there!"
474496 ]
475497 ++ typicalHints
476498
@@ -487,9 +509,9 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
487509 Manager name ->
488510 report
489511 Nothing
490− ("The `" ++ name ++ "` in your effect manager has a weird type.")
512+ ("The `" <> name <> "` in your effect manager has a weird type.")
491513 ( cmpHint
492− ("Your `" ++ name ++ "` function has this type:")
514+ ("Your `" <> name <> "` function has this type:")
493515 "But it needs to have a type like this:"
494516 [ "You can read more about setting up effect managers properly here:\
495517 \ <http://guide.elm-lang.org/effect_managers/>"
@@ -500,11 +522,11 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
500522 report
501523 Nothing
502524 ( "Your effect manager creates a certain type of state with `init`, but your `"
503− ++ name ++ "` function expects a different kind of state."
525+ <> name <> "` function expects a different kind of state."
504526 )
505527 ( cmpHint
506528 "The state created by `init` has this type:"
507− ("But `" ++ name ++ "` expects state of this type:")
529+ ("But `" <> name <> "` expects state of this type:")
508530 [ "Make the two state types match and you should be all set! More info here:\
509531 \ <http://guide.elm-lang.org/effect_managers/>"
510532 ]
@@ -529,8 +551,8 @@ comparisonHint
529551 :: RenderType.Localizer
530552 -> Type.Canonical
531553 -> Type.Canonical
532− -> String
533− -> String
554+ -> Text
555+ -> Text
534556 -> [Doc]
535557 -> Doc
536558comparisonHint localizer leftType rightType leftWords rightWords finalHints =
@@ -538,10 +560,10 @@ comparisonHint localizer leftType rightType leftWords rightWords finalHints =
538560 (leftDoc, rightDoc) =
539561 RenderType.diffToDocs localizer leftType rightType
540562 in
541− Help.stack $
542− [ Help.reflowParagraph leftWords
563+ stack $
564+ [ reflowParagraph leftWords
543565 , indent 4 leftDoc
544− , Help.reflowParagraph rightWords
566+ , reflowParagraph rightWords
545567 , indent 4 rightDoc
546568 ]
547569 ++
@@ -552,7 +574,7 @@ comparisonHint localizer leftType rightType leftWords rightWords finalHints =
552574-- BINOP HINTS
553575
554576
555−binopHint :: Var.Canonical -> Type.Canonical -> Type.Canonical -> [String]
577+binopHint :: Var.Canonical -> Type.Canonical -> Type.Canonical -> [Text]
556578binopHint op leftType rightType =
557579 let
558580 leftString =
@@ -561,12 +583,12 @@ binopHint op leftType rightType =
561583 rightString =
562584 show (RenderType.toDoc Map.empty rightType)
563585 in
564− if Var.is ["Basics"] "+" op && elem "String" [leftString, rightString] then
565− [ "To append strings in Elm, you need to use the (++) operator, not (+). "
566− ++ "<http://package.elm-lang.org/packages/elm-lang/core/latest/Basics#++>"
586+ if Var.is "Basics" "+" op && elem "String" [leftString, rightString] then
587+ [ "To append strings in Elm, you need to use the (++) operator, not (+).\
588+ \ <http://package.elm-lang.org/packages/elm-lang/core/latest/Basics#++>"
567589 ]
568590
569− else if Var.is ["Basics"] "/" op && elem "Int" [leftString, rightString] then
591+ else if Var.is "Basics" "/" op && elem "Int" [leftString, rightString] then
570592 [ "The (/) operator is specifically for floating point division, and (//) is\
571593 \ for integer division. You may need to do some conversions between ints and\
572594 \ floats to get both arguments matching the division operator you want."
@@ -580,14 +602,14 @@ binopHint op leftType rightType =
580602-- FUNCTION HINTS
581603
582604
583−functionHint :: Maybe Var.Canonical -> [String]
605+functionHint :: Maybe Var.Canonical -> [Text]
584606functionHint maybeName =
585607 case maybeName of
586608 Nothing ->
587609 []
588610
589611 Just name ->
590− if Var.inHtml ["Html","App"] "program" == name then
612+ if Var.inHtml "Html" "program" == name then
591613 [ "Does your program have flags? Maybe you want `programWithFlags` instead."
592614 ]
593615
@@ -599,20 +621,21 @@ functionHint maybeName =
599621-- ARITY HINTS
600622
601623
602−arityHint :: Int -> Int -> [String]
624+arityHint :: Int -> Int -> [Text]
603625arityHint typeArity argArity =
604626 if typeArity == argArity then
605627 []
606628
607629 else
608− [ "The type annotation says there " ++ sayArgs typeArity
609− ++ ", but there " ++ sayArgs argArity ++ " named in the definition."
610− ++ " It is best practice for each argument in the type to correspond"
611− ++ " to a named argument in the definition, so try that first!"
630+ [ "The type annotation says there " <> sayArgs typeArity <>
631+ ", but there " <> sayArgs argArity <>
632+ " named in the definition. It is best practice for each argument\
633+ \ in the type to correspond to a named argument in the definition,\
634+ \ so try that first!"
612635 ]
613636
614637
615−sayArgs :: Int -> String
638+sayArgs :: Int -> Text
616639sayArgs n =
617640 case n of
618641 0 ->
@@ -622,31 +645,31 @@ sayArgs n =
622645 "is 1 argument"
623646
624647 _ ->
625− "are " ++ show n ++ " arguments"
648+ "are " <> i2t n <> " arguments"
626649
627650
628651
629652-- MISMATCH HELPERS
630653
631654
632−ordinalPair :: Int -> String
655+ordinalPair :: Int -> Text
633656ordinalPair number =
634− Help.ordinalize (number -1 ) ++ " and " ++ Help.ordinalize number
657+ ordinalize (number - 1) <> " and " <> ordinalize number
635658
636659
637−prettyName :: Var.Canonical -> String
638−prettyName (Var.Canonical _ opName) =
639− Help.functionName opName
660+varName :: Var.Canonical -> Text
661+varName (Var.Canonical _ opName) =
662+ functionName opName
640663
641664
642−funcName :: Maybe Var.Canonical -> String
643−funcName maybeVar =
665+maybeFuncName :: Maybe Var.Canonical -> Text
666+maybeFuncName maybeVar =
644667 case maybeVar of
645668 Nothing ->
646669 "this function"
647670
648671 Just var ->
649− "function " ++ prettyName var
672+ "function " <> varName var
650673
651674
652675
@@ -690,26 +713,26 @@ reasonToString reason =
690713 Nothing
691714
692715 [field] ->
693− Just $ "Problem in the `" ++ field ++ "` field. "
716+ Just $ "Problem in the `" <> field <> "` field. "
694717
695718 _ ->
696− Just $ "Problem at `" ++ List.intercalate "." fields ++ "`. "
719+ Just $ "Problem at `" <> Text.intercalate "." fields <> "`. "
697720 in
698721 case (starter, maybeDocs) of
699722 (Nothing, Nothing) ->
700723 Nothing
701724
702725 (Just msg, Nothing) ->
703− Just $ toHint (msg ++ badFieldElaboration)
726+ Just $ toHint (msg <> badFieldElaboration)
704727
705728 (_, Just (firstLine, docs)) ->
706729 Just $ vcat $
707− toHint (maybe firstLine (++firstLine) starter)
730+ toHint (maybe firstLine (<> firstLine) starter)
708731 : map (indent 4) docs
709732
710733
711734
712−collectFields :: Reason -> ([String], Maybe Reason)
735+collectFields :: Reason -> ([Text], Maybe Reason)
713736collectFields reason =
714737 case reason of
715738 BadFields [(field, Nothing)] ->
@@ -722,7 +745,7 @@ collectFields reason =
722745 ([], Just reason)
723746
724747
725−reasonToStringHelp :: Reason -> Maybe (String, [Doc])
748+reasonToStringHelp :: Reason -> Maybe (Text, [Doc])
726749reasonToStringHelp reason =
727750 let
728751 go msg =
@@ -732,8 +755,8 @@ reasonToStringHelp reason =
732755 BadFields fields ->
733756 go $
734757 "I am seeing issues with the "
735− ++ Help.commaSep (map fst fields) ++ " fields. "
736− ++ badFieldElaboration
758+ <> Help.commaSep (map fst fields) <> " fields. "
759+ <> badFieldElaboration
737760
738761 MessyFields both leftOnly rightOnly ->
739762 messyFieldsHelp both leftOnly rightOnly
@@ -747,12 +770,11 @@ reasonToStringHelp reason =
747770 TooLongComparableTuple len ->
748771 go $
749772 "Although tuples are comparable, this is currently only supported\
750− \ for tuples with 6 or fewer entries, not " ++ show len ++ "."
773+ \ for tuples with 6 or fewer entries, not " <> i2t len <> "."
751774
752775 MissingArgs num ->
753776 go $
754− "It looks like a function needs " ++ show num ++ " more "
755− ++ (if num == 1 then "argument" else "arguments") ++ "."
777+ "It looks like a function needs " <> i2t num <> " more" <> Help.args num <> "."
756778
757779 BadVar (Just Comparable) _ ->
758780 go "Only ints, floats, chars, strings, lists, and tuples are comparable."
@@ -776,48 +798,48 @@ reasonToStringHelp reason =
776798 Nothing
777799
778800
779−badFieldElaboration :: String
801+badFieldElaboration :: Text
780802badFieldElaboration =
781803 "I always figure out field types in alphabetical order. If a field\
782804 \ seems fine, I assume it is \"correct\" in subsequent checks.\
783805 \ So the problem may actually be a weird interaction with previous fields."
784806
785807
786−weirdRigidError :: String
808+weirdRigidError :: Text
787809weirdRigidError =
788810 "You are having a problem with \"rigid\" type variables. That usually\
789811 \ means you have a type annotation that says it accepts anything, but\
790812 \ in fact, it accepts a much more specific type. More info at: "
791− ++ Help.hintLink "type-annotations" ++
813+ <> Help.hintLink "type-annotations" <>
792814 ". This case is weird though, so please turn it into an <http://sscce.org>\
793815 \ and report it to <https://github.com/elm-lang/error-message-catalog>."
794816
795817
796−singleRigidError :: Maybe String -> String
818+singleRigidError :: Maybe Text -> Text
797819singleRigidError maybeName =
798820 case maybeName of
799821 Just name ->
800− "Your type annotation uses type variable `" ++ name ++
822+ "Your type annotation uses type variable `" <> name <>
801823 "` which means any type of value can flow through. Your code is saying\
802824 \ it CANNOT be anything though! Maybe change your type annotation to\
803825 \ be more specific? Maybe the code has a problem? More at: "
804− ++ Help.hintLink "type-annotations"
826+ <> Help.hintLink "type-annotations"
805827
806828 Nothing ->
807829 weirdRigidError
808830
809831
810−doubleRigidError :: Maybe String -> Maybe String -> String
832+doubleRigidError :: Maybe Text -> Maybe Text -> Text
811833doubleRigidError maybeLeftName maybeRightName =
812834 case (maybeLeftName, maybeRightName) of
813835 (Just leftName, Just rightName) ->
814− "Your type annotation uses `" ++ leftName ++ "` and `" ++ rightName ++
836+ "Your type annotation uses `" <> leftName <> "` and `" <> rightName <>
815837 "` as separate type variables. Each one can be any type of value,\
816838 \ but because they have separate names, there is no guarantee that they\
817839 \ are equal to each other. Your code seems to be saying they ARE the\
818840 \ same though! Maybe they should be the same in your type annotation?\
819841 \ Maybe your code uses them in a weird way? More at: "
820− ++ Help.hintLink "type-annotations"
842+ <> Help.hintLink "type-annotations"
821843
822844 _ ->
823845 weirdRigidError
@@ -828,12 +850,12 @@ hintDoc =
828850 underline (text "Hint") <> colon
829851
830852
831−toHint :: String -> Doc
832−toHint str =
833− fillSep (hintDoc : map text (words str))
853+toHint :: Text -> Doc
854+toHint txt =
855+ fillSep (hintDoc : map text (Text.words txt))
834856
835857
836−messyFieldsHelp :: [String] -> [String] -> [String] -> Maybe (String, [Doc])
858+messyFieldsHelp :: [Text] -> [Text] -> [Text] -> Maybe (Text, [Doc])
837859messyFieldsHelp both leftOnly rightOnly =
838860 case (leftOnly, rightOnly) of
839861 ([], [missingField]) ->
@@ -861,8 +883,8 @@ messyFieldsHelp both leftOnly rightOnly =
861883 if null typoPairs then
862884 Just
863885 ( "The record fields do not match up. One has "
864− ++ Help.commaSep leftOnly ++ ". The other has "
865− ++ Help.commaSep rightOnly ++ "."
886+ <> Help.commaSep leftOnly <> ". The other has "
887+ <> Help.commaSep rightOnly <> "."
866888 , []
867889 )
868890
@@ -873,61 +895,62 @@ messyFieldsHelp both leftOnly rightOnly =
873895 )
874896
875897
876−oneMissingField :: [String] -> String -> Maybe (String, [Doc])
898+oneMissingField :: [Text] -> Text -> Maybe (Text, [Doc])
877899oneMissingField knownFields missingField =
878900 case Help.findPotentialTypos knownFields missingField of
879901 [] ->
880902 Just
881− ( "Looks like a record is missing the `" ++ missingField ++ "` field."
903+ ( "Looks like a record is missing the `" <> missingField <> "` field."
882904 , []
883905 )
884906
885907 [typo] ->
886908 Just
887− ( "Looks like a record is missing the `" ++ missingField
888− ++ "` field. Maybe it is a typo?"
909+ ( "Looks like a record is missing the `" <> missingField
910+ <> "` field. Maybe it is a typo?"
889911 , typoDocs "->" [(missingField, typo)]
890912 )
891913
892914 typos ->
893915 Just
894− ( "Looks like a record is missing the `" ++ missingField
895− ++ "` field. It is close to names like "
896− ++ Help.commaSep typos ++ " so maybe it is a typo?"
916+ ( "Looks like a record is missing the `" <> missingField
917+ <> "` field. It is close to names like "
918+ <> Help.commaSep typos <> " so maybe it is a typo?"
897919 , []
898920 )
899921
900922
901−manyMissingFields :: [String] -> [String] -> Maybe (String, [Doc])
923+manyMissingFields :: [Text] -> [Text] -> Maybe (Text, [Doc])
902924manyMissingFields knownFields missingFields =
903925 case Help.findTypoPairs missingFields knownFields of
904926 [] ->
905927 Just
906928 ( "Looks like a record is missing these fields: "
907− ++ Help.commaSep missingFields
929+ <> Help.commaSep missingFields
908930 , []
909931 )
910932
911933 typoPairs ->
912934 Just
913− ( "Looks like a record is missing these fields: " ++ Help.commaSep missingFields
914− ++ ". Potential typos include:"
935+ ( "Looks like a record is missing these fields: "
936+ <> Help.commaSep missingFields
937+ <> ". Potential typos include:"
915938 , typoDocs "->" typoPairs
916939 )
917940
918941
919−typoDocs :: String -> [(String, String)] -> [Doc]
942+typoDocs :: Text -> [(Text, Text)] -> [Doc]
920943typoDocs arrow typoPairs =
921944 let
922945 maxLen =
923− maximum (map (length . fst) typoPairs)
946+ maximum (map (Text.length . fst) typoPairs)
924947 in
925948 text "" : map (padTypo arrow maxLen) typoPairs
926949
927950
928−padTypo :: String -> Int -> (String, String) -> Doc
951+padTypo :: Text -> Int -> (Text, Text) -> Doc
929952padTypo arrow maxLen (missingField, knownField) =
930− text (replicate (maxLen - length missingField) ' ')
953+ text (Text.replicate (maxLen - Text.length missingField) " ")
931954 <> dullyellow (text missingField)
932955 <+> text arrow
933956 <+> dullyellow (text knownField)
@@ -939,24 +962,23 @@ padTypo arrow maxLen (missingField, knownField) =
939962
940963infiniteTypeToReport
941964 :: RenderType.Localizer
942− -> String
965+ -> Text
943966 -> Type.Canonical
944967 -> Report.Report
945968infiniteTypeToReport localizer name overallType =
946969 Report.report
947970 "INFINITE TYPE"
948971 Nothing
949− ( "I am inferring a weird self-referential type for " ++ Help.functionName name
972+ ( "I am inferring a weird self-referential type for " <> functionName name
950973 )
951− ( Help.stack
952− [ Help.reflowParagraph $
974+ ( stack
975+ [ reflowParagraph $
953976 "Here is my best effort at writing down the type. You will see ? and ∞ for\
954977 \ parts of the type that repeat something already printed out infinitely."
955978 , indent 4 (RenderType.toDoc localizer overallType)
956− , Help.reflowParagraph $
979+ , reflowParagraph $
957980 "Usually staring at the type is not so helpful in these cases, so definitely\
958981 \ read the debugging hints for ideas on how to figure this out: "
959− ++ Help.hintLink "infinite-type"
982+ <> Help.hintLink "infinite-type"
960983 ]
961984 )
962−