@@ -18,10 +18,12 @@ import Data.Char (isSpace)
1818import Data.Either (lefts, rights)
1919import Data.Foldable (fold)
2020import Data.Functor.Identity (Identity(..))
21−import Data.List (intercalate, transpose, nub, nubBy, sortBy, partition)
21+import Data.List (transpose, nub, nubBy, sortBy, partition)
2222import Data.Maybe (maybeToList, fromMaybe, mapMaybe)
2323import Data.Ord (comparing)
2424import qualified Data.Map as M
25+import qualified Data.Text as T
26+import Data.Text (Text)
2527
2628import Language.PureScript.AST
2729import Language.PureScript.Crash
@@ -43,7 +45,7 @@ import qualified Text.PrettyPrint.Boxes as Box
4345import qualified Language.PureScript.Publish.BoxesHelpers as BoxHelpers
4446import Text.Parsec.Error (Message(..))
4547
46−newtype ErrorSuggestion = ErrorSuggestion String
48+newtype ErrorSuggestion = ErrorSuggestion Text
4749
4850-- | Get the source span for an error
4951errorSpan :: ErrorMessage -> Maybe SourceSpan
@@ -73,7 +75,7 @@ stripModuleAndSpan (ErrorMessage hints e) = ErrorMessage (filter (not . shouldSt
7375-- |
7476-- Get the error code for a particular error type
7577--
76−errorCode :: ErrorMessage -> String
78+errorCode :: ErrorMessage -> Text
7779errorCode em = case unwrapErrorMessage em of
7880 ErrorParsingFFIModule{} -> "ErrorParsingFFIModule"
7981 ErrorParsingModule{} -> "ErrorParsingModule"
@@ -245,7 +247,7 @@ replaceUnknowns = everywhereOnTypesM replaceTypes
245247 case M.lookup s (umSkolemMap m) of
246248 Nothing -> do
247249 let s' = umNextIndex m
248− put $ m { umSkolemMap = M.insert s (name, s', ss) (umSkolemMap m), umNextIndex = s' + 1 }
250+ put $ m { umSkolemMap = M.insert s (T.unpack name, s', ss) (umSkolemMap m), umNextIndex = s' + 1 }
249251 return (Skolem name s' sko ss)
250252 Just (_, s', _) -> return (Skolem name s' sko ss)
251253 replaceTypes other = return other
@@ -287,8 +289,8 @@ onTypesInErrorMessageM f (ErrorMessage hints simple) = ErrorMessage <$> traverse
287289 gTypeSearch (TSBefore env) = pure (TSBefore env)
288290 gTypeSearch (TSAfter result) = TSAfter <$> traverse (traverse f) result
289291
290−wikiUri :: ErrorMessage -> String
291−wikiUri e = "https://github.com/purescript/purescript/wiki/Error-Code-" ++ errorCode e
292+wikiUri :: ErrorMessage -> Text
293+wikiUri e = "https://github.com/purescript/purescript/wiki/Error-Code-" <> errorCode e
292294
293295-- TODO Other possible suggestions:
294296-- WildcardInferredType - source span not small enough
@@ -304,19 +306,19 @@ errorSuggestion err =
304306 ImplicitImport mn refs -> suggest $ importSuggestion mn refs Nothing
305307 ImplicitQualifiedImport mn asModule refs -> suggest $ importSuggestion mn refs (Just asModule)
306308 HidingImport mn refs -> suggest $ importSuggestion mn refs Nothing
307− MissingTypeDeclaration ident ty -> suggest $ showIdent ident ++ " :: " ++ prettyPrintSuggestedType ty
308− WildcardInferredType ty _ -> suggest $ prettyPrintSuggestedType ty
309+ MissingTypeDeclaration ident ty -> suggest $ showIdent ident <> " :: " <> T.pack (prettyPrintSuggestedType ty)
310+ WildcardInferredType ty _ -> suggest $ T.pack (prettyPrintSuggestedType ty)
309311 _ -> Nothing
310312 where
311313 emptySuggestion = Just $ ErrorSuggestion ""
312314 suggest = Just . ErrorSuggestion
313315
314− importSuggestion :: ModuleName -> [ DeclarationRef ] -> Maybe ModuleName -> String
316+ importSuggestion :: ModuleName -> [ DeclarationRef ] -> Maybe ModuleName -> Text
315317 importSuggestion mn refs qual =
316− "import " ++ runModuleName mn ++ " (" ++ intercalate ", " (mapMaybe prettyPrintRef refs) ++ ")" ++ qstr qual
318+ "import " <> runModuleName mn <> " (" <> T.intercalate ", " (mapMaybe prettyPrintRef refs) <> ")" <> qstr qual
317319
318− qstr :: Maybe ModuleName -> String
319− qstr (Just mn) = " as " ++ runModuleName mn
320+ qstr :: Maybe ModuleName -> Text
321+ qstr (Just mn) = " as " <> runModuleName mn
320322 qstr Nothing = ""
321323
322324suggestionSpan :: ErrorMessage -> Maybe SourceSpan
@@ -330,7 +332,7 @@ suggestionSpan e =
330332 MissingTypeDeclaration{} -> startOnly ss
331333 _ -> ss
332334
333−showSuggestion :: SimpleErrorMessage -> String
335+showSuggestion :: SimpleErrorMessage -> Text
334336showSuggestion suggestion = case errorSuggestion suggestion of
335337 Just (ErrorSuggestion x) -> x
336338 _ -> ""
@@ -343,10 +345,10 @@ ansiColorReset :: String
343345ansiColorReset =
344346 ANSI.setSGRCode [ANSI.Reset]
345347
346−colorCode :: Maybe (ANSI.ColorIntensity, ANSI.Color) -> String -> String
348+colorCode :: Maybe (ANSI.ColorIntensity, ANSI.Color) -> Text -> Text
347349colorCode codeColor code = case codeColor of
348350 Nothing -> code
349− Just cc -> concat [ansiColor cc, code, ansiColorReset]
351+ Just cc -> T.pack (ansiColor cc) <> code <> T.pack ansiColorReset
350352
351353colorCodeBox :: Maybe (ANSI.ColorIntensity, ANSI.Color) -> Box.Box -> Box.Box
352354colorCodeBox codeColor b = case codeColor of
@@ -403,8 +405,8 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
403405 ] ++
404406 maybe [] (return . Box.moveDown 1) typeInformation ++
405407 [ Box.moveDown 1 $ paras
406− [ line $ "See " ++ wikiUri e ++ " for more information, "
407− , line $ "or to contribute content related to this " ++ levelText ++ "."
408+ [ line $ "See " <> wikiUri e <> " for more information, "
409+ , line $ "or to contribute content related to this " <> levelText <> "."
408410 ]
409411 | showWiki
410412 ]
@@ -420,59 +422,59 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
420422 skolemInfo :: (String, Int, Maybe SourceSpan) -> Box.Box
421423 skolemInfo (name, s, ss) =
422424 paras $
423− line (markCode (name ++ show s) ++ " is a rigid type variable")
424− : foldMap (return . line . (" bound at " ++) . displayStartEndPos) ss
425+ line (markCode (T.pack (name <> show s)) <> " is a rigid type variable")
426+ : foldMap (return . line . (" bound at " <>) . displayStartEndPos) ss
425427
426428 unknownInfo :: Int -> Box.Box
427− unknownInfo u = line $ markCode ("t" ++ show u) ++ " is an unknown type"
429+ unknownInfo u = line $ markCode ("t" <> T.pack (show u)) <> " is an unknown type"
428430
429431 renderSimpleErrorMessage :: SimpleErrorMessage -> Box.Box
430432 renderSimpleErrorMessage (CannotGetFileInfo path) =
431433 paras [ line "Unable to read file info: "
432− , indent . line $ path
434+ , indent . lineS $ path
433435 ]
434436 renderSimpleErrorMessage (CannotReadFile path) =
435437 paras [ line "Unable to read file: "
436− , indent . line $ path
438+ , indent . lineS $ path
437439 ]
438440 renderSimpleErrorMessage (CannotWriteFile path) =
439441 paras [ line "Unable to write file: "
440− , indent . line $ path
442+ , indent . lineS $ path
441443 ]
442444 renderSimpleErrorMessage (ErrorParsingFFIModule path extra) =
443445 paras $ [ line "Unable to parse foreign module:"
444− , indent . line $ path
446+ , indent . lineS $ path
445447 ] ++
446− map (indent . line) (concatMap Bundle.printErrorMessage (maybeToList extra))
448+ map (indent . lineS) (concatMap Bundle.printErrorMessage (maybeToList extra))
447449 renderSimpleErrorMessage (ErrorParsingModule err) =
448450 paras [ line "Unable to parse module: "
449451 , prettyPrintParseError err
450452 ]
451453 renderSimpleErrorMessage (MissingFFIModule mn) =
452− line $ "The foreign module implementation for module " ++ markCode (runModuleName mn) ++ " is missing."
454+ line $ "The foreign module implementation for module " <> markCode (runModuleName mn) <> " is missing."
453455 renderSimpleErrorMessage (UnnecessaryFFIModule mn path) =
454− paras [ line $ "An unnecessary foreign module implementation was provided for module " ++ markCode (runModuleName mn) ++ ": "
455− , indent . line $ path
456− , line $ "Module " ++ markCode (runModuleName mn) ++ " does not contain any foreign import declarations, so a foreign module is not necessary."
456+ paras [ line $ "An unnecessary foreign module implementation was provided for module " <> markCode (runModuleName mn) <> ": "
457+ , indent . lineS $ path
458+ , line $ "Module " <> markCode (runModuleName mn) <> " does not contain any foreign import declarations, so a foreign module is not necessary."
457459 ]
458460 renderSimpleErrorMessage (MissingFFIImplementations mn idents) =
459− paras [ line $ "The following values are not defined in the foreign module for module " ++ markCode (runModuleName mn) ++ ": "
461+ paras [ line $ "The following values are not defined in the foreign module for module " <> markCode (runModuleName mn) <> ": "
460462 , indent . paras $ map (line . runIdent) idents
461463 ]
462464 renderSimpleErrorMessage (UnusedFFIImplementations mn idents) =
463− paras [ line $ "The following definitions in the foreign module for module " ++ markCode (runModuleName mn) ++ " are unused: "
465+ paras [ line $ "The following definitions in the foreign module for module " <> markCode (runModuleName mn) <> " are unused: "
464466 , indent . paras $ map (line . runIdent) idents
465467 ]
466468 renderSimpleErrorMessage (InvalidFFIIdentifier mn ident) =
467− paras [ line $ "In the FFI module for " ++ markCode (runModuleName mn) ++ ":"
469+ paras [ line $ "In the FFI module for " <> markCode (runModuleName mn) <> ":"
468470 , indent . paras $
469− [ line $ "The identifier " ++ markCode ident ++ " is not valid in PureScript."
471+ [ line $ "The identifier " <> markCode ident <> " is not valid in PureScript."
470472 , line "Note that exported identifiers in FFI modules must be valid PureScript identifiers."
471473 ]
472474 ]
473475 renderSimpleErrorMessage (MultipleFFIModules mn paths) =
474− paras [ line $ "Multiple foreign module implementations have been provided for module " ++ markCode (runModuleName mn) ++ ": "
475− , indent . paras $ map line paths
476+ paras [ line $ "Multiple foreign module implementations have been provided for module " <> markCode (runModuleName mn) <> ": "
477+ , indent . paras $ map lineS paths
476478 ]
477479 renderSimpleErrorMessage InvalidDoBind =
478480 line "The last statement in a 'do' block must be an expression, but this block ends with a binder."
@@ -489,63 +491,63 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
489491 , indent $ line $ markCode $ prettyPrintKind ki
490492 ]
491493 renderSimpleErrorMessage (MultipleValueOpFixities op) =
492− line $ "There are multiple fixity/precedence declarations for operator " ++ markCode (showOp op)
494+ line $ "There are multiple fixity/precedence declarations for operator " <> markCode (showOp op)
493495 renderSimpleErrorMessage (MultipleTypeOpFixities op) =
494− line $ "There are multiple fixity/precedence declarations for type operator " ++ markCode (showOp op)
496+ line $ "There are multiple fixity/precedence declarations for type operator " <> markCode (showOp op)
495497 renderSimpleErrorMessage (OrphanTypeDeclaration nm) =
496− line $ "The type declaration for " ++ markCode (showIdent nm) ++ " should be followed by its definition."
498+ line $ "The type declaration for " <> markCode (showIdent nm) <> " should be followed by its definition."
497499 renderSimpleErrorMessage (RedefinedIdent name) =
498− line $ "The value " ++ markCode (showIdent name) ++ " has been defined multiple times"
500+ line $ "The value " <> markCode (showIdent name) <> " has been defined multiple times"
499501 renderSimpleErrorMessage (UnknownName name) =
500− line $ "Unknown " ++ printName name
502+ line $ "Unknown " <> printName name
501503 renderSimpleErrorMessage (UnknownImport mn name) =
502− paras [ line $ "Cannot import " ++ printName (Qualified Nothing name) ++ " from module " ++ markCode (runModuleName mn)
504+ paras [ line $ "Cannot import " <> printName (Qualified Nothing name) <> " from module " <> markCode (runModuleName mn)
503505 , line "It either does not exist or the module does not export it."
504506 ]
505507 renderSimpleErrorMessage (UnknownImportDataConstructor mn tcon dcon) =
506− line $ "Module " ++ runModuleName mn ++ " does not export data constructor " ++ markCode (runProperName dcon) ++ " for type " ++ markCode (runProperName tcon)
508+ line $ "Module " <> runModuleName mn <> " does not export data constructor " <> markCode (runProperName dcon) <> " for type " <> markCode (runProperName tcon)
507509 renderSimpleErrorMessage (UnknownExport name) =
508− line $ "Cannot export unknown " ++ printName (Qualified Nothing name)
510+ line $ "Cannot export unknown " <> printName (Qualified Nothing name)
509511 renderSimpleErrorMessage (UnknownExportDataConstructor tcon dcon) =
510− line $ "Cannot export data constructor " ++ markCode (runProperName dcon) ++ " for type " ++ markCode (runProperName tcon) ++ ", as it has not been declared."
512+ line $ "Cannot export data constructor " <> markCode (runProperName dcon) <> " for type " <> markCode (runProperName tcon) <> ", as it has not been declared."
511513 renderSimpleErrorMessage (ScopeConflict nm ms) =
512− paras [ line $ "Conflicting definitions are in scope for " ++ printName (Qualified Nothing nm) ++ " from the following modules:"
514+ paras [ line $ "Conflicting definitions are in scope for " <> printName (Qualified Nothing nm) <> " from the following modules:"
513515 , indent $ paras $ map (line . markCode . runModuleName) ms
514516 ]
515517 renderSimpleErrorMessage (ScopeShadowing nm exmn ms) =
516− paras [ line $ "Shadowed definitions are in scope for " ++ printName (Qualified Nothing nm) ++ " from the following open imports:"
517− , indent $ paras $ map (line . markCode . ("import " ++) . runModuleName) ms
518− , line $ "These will be ignored and the " ++ case exmn of
519− Just exmn' -> "declaration from " ++ markCode (runModuleName exmn') ++ " will be used."
518+ paras [ line $ "Shadowed definitions are in scope for " <> printName (Qualified Nothing nm) <> " from the following open imports:"
519+ , indent $ paras $ map (line . markCode . ("import " <>) . runModuleName) ms
520+ , line $ "These will be ignored and the " <> case exmn of
521+ Just exmn' -> "declaration from " <> markCode (runModuleName exmn') <> " will be used."
520522 Nothing -> "local declaration will be used."
521523 ]
522524 renderSimpleErrorMessage (DeclConflict new existing) =
523− line $ "Declaration for " ++ printName (Qualified Nothing new) ++ " conflicts with an existing " ++ nameType existing ++ " of the same name."
525+ line $ "Declaration for " <> printName (Qualified Nothing new) <> " conflicts with an existing " <> nameType existing <> " of the same name."
524526 renderSimpleErrorMessage (ExportConflict new existing) =
525− line $ "Export for " ++ printName new ++ " conflicts with " ++ runName existing
527+ line $ "Export for " <> printName new <> " conflicts with " <> runName existing
526528 renderSimpleErrorMessage (DuplicateModule mn ss) =
527− paras [ line ("Module " ++ markCode (runModuleName mn) ++ " has been defined multiple times:")
529+ paras [ line ("Module " <> markCode (runModuleName mn) <> " has been defined multiple times:")
528530 , indent . paras $ map (line . displaySourceSpan) ss
529531 ]
530532 renderSimpleErrorMessage (CycleInDeclaration nm) =
531− line $ "The value of " ++ markCode (showIdent nm) ++ " is undefined here, so this reference is not allowed."
533+ line $ "The value of " <> markCode (showIdent nm) <> " is undefined here, so this reference is not allowed."
532534 renderSimpleErrorMessage (CycleInModules mns) =
533535 paras [ line "There is a cycle in module dependencies in these modules: "
534536 , indent $ paras (map (line . markCode . runModuleName) mns)
535537 ]
536538 renderSimpleErrorMessage (CycleInTypeSynonym name) =
537539 paras [ line $ case name of
538− Just pn -> "A cycle appears in the definition of type synonym " ++ markCode (runProperName pn)
540+ Just pn -> "A cycle appears in the definition of type synonym " <> markCode (runProperName pn)
539541 Nothing -> "A cycle appears in a set of type synonym definitions."
540542 , line "Cycles are disallowed because they can lead to loops in the type checker."
541543 , line "Consider using a 'newtype' instead."
542544 ]
543545 renderSimpleErrorMessage (NameIsUndefined ident) =
544− line $ "Value " ++ markCode (showIdent ident) ++ " is undefined."
546+ line $ "Value " <> markCode (showIdent ident) <> " is undefined."
545547 renderSimpleErrorMessage (UndefinedTypeVariable name) =
546− line $ "Type variable " ++ markCode (runProperName name) ++ " is undefined."
548+ line $ "Type variable " <> markCode (runProperName name) <> " is undefined."
547549 renderSimpleErrorMessage (PartiallyAppliedSynonym name) =
548− paras [ line $ "Type synonym " ++ markCode (showQualified runProperName name) ++ " is partially applied."
550+ paras [ line $ "Type synonym " <> markCode (showQualified runProperName name) <> " is partially applied."
549551 , line "Type synonyms must be applied to all of their type arguments."
550552 ]
551553 renderSimpleErrorMessage (EscapedSkolem binding) =
@@ -561,12 +563,12 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
561563 sortRows t1 t2 = (t1, t2)
562564
563565 -- Put the common labels last
564− sortRows' :: ([(String, Type)], Type) -> ([(String, Type)], Type) -> (Type, Type)
566+ sortRows' :: ([(Text, Type)], Type) -> ([(Text, Type)], Type) -> (Type, Type)
565567 sortRows' (s1, r1) (s2, r2) =
566− let common :: [(String, (Type, Type))]
568+ let common :: [(Text, (Type, Type))]
567569 common = sortBy (comparing fst) [ (name, (t1, t2)) | (name, t1) <- s1, (name', t2) <- s2, name == name' ]
568570
569− sd1, sd2 :: [(String, Type)]
571+ sd1, sd2 :: [(Text, Type)]
570572 sd1 = [ (name, t1) | (name, t1) <- s1, name `notElem` map fst s2 ]
571573 sd2 = [ (name, t2) | (name, t2) <- s2, name `notElem` map fst s1 ]
572574 in ( rowFromList (sortBy (comparing fst) sd1 ++ map (fst &&& fst . snd) common, r1)
@@ -597,7 +599,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
597599 , Box.vcat Box.left (map typeAtomAsBox ts)
598600 ]
599601 , line "The following instances were found:"
600− , indent $ paras (line (showQualified showIdent d ++ " (chosen)") : map (line . showQualified showIdent) ds)
602+ , indent $ paras (line (showQualified showIdent d <> " (chosen)") : map (line . showQualified showIdent) ds)
601603 , line "Overlapping type class instances can lead to different behavior based on the order of module imports, and for that reason are not recommended."
602604 , line "They may be disallowed completely in a future version of the compiler."
603605 ]
@@ -667,26 +669,26 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
667669 , line "Make sure this is a newtype."
668670 ]
669671 renderSimpleErrorMessage (CannotFindDerivingType nm) =
670− line $ "Cannot derive a type class instance, because the type declaration for " ++ markCode (runProperName nm) ++ " could not be found."
672+ line $ "Cannot derive a type class instance, because the type declaration for " <> markCode (runProperName nm) <> " could not be found."
671673 renderSimpleErrorMessage (DuplicateLabel l expr) =
672− paras $ [ line $ "Label " ++ markCode l ++ " appears more than once in a row type." ]
674+ paras $ [ line $ "Label " <> markCode l <> " appears more than once in a row type." ]
673675 <> foldMap (\expr' -> [ line "Relevant expression: "
674676 , markCodeBox $ indent $ prettyPrintValue valueDepth expr'
675677 ]) expr
676678 renderSimpleErrorMessage (DuplicateTypeArgument name) =
677− line $ "Type argument " ++ markCode name ++ " appears more than once."
679+ line $ "Type argument " <> markCode name <> " appears more than once."
678680 renderSimpleErrorMessage (DuplicateValueDeclaration nm) =
679− line $ "Multiple value declarations exist for " ++ markCode (showIdent nm) ++ "."
681+ line $ "Multiple value declarations exist for " <> markCode (showIdent nm) <> "."
680682 renderSimpleErrorMessage (ArgListLengthsDiffer ident) =
681− line $ "Argument list lengths differ in declaration " ++ markCode (showIdent ident)
683+ line $ "Argument list lengths differ in declaration " <> markCode (showIdent ident)
682684 renderSimpleErrorMessage (OverlappingArgNames ident) =
683− line $ "Overlapping names in function/binder" ++ foldMap ((" in declaration " ++) . showIdent) ident
685+ line $ "Overlapping names in function/binder" <> foldMap ((" in declaration " <>) . showIdent) ident
684686 renderSimpleErrorMessage (MissingClassMember ident) =
685− line $ "Type class member " ++ markCode (showIdent ident) ++ " has not been implemented."
687+ line $ "Type class member " <> markCode (showIdent ident) <> " has not been implemented."
686688 renderSimpleErrorMessage (ExtraneousClassMember ident className) =
687− line $ "" ++ markCode (showIdent ident) ++ " is not a member of type class " ++ markCode (showQualified runProperName className)
689+ line $ "" <> markCode (showIdent ident) <> " is not a member of type class " <> markCode (showQualified runProperName className)
688690 renderSimpleErrorMessage (ExpectedType ty kind) =
689− paras [ line $ "In a type-annotated expression " ++ markCode "x :: t" ++ ", the type " ++ markCode "t" ++ " must have kind " ++ markCode "*" ++ "."
691+ paras [ line $ "In a type-annotated expression " <> markCode "x :: t" <> ", the type " <> markCode "t" <> " must have kind " <> markCode "*" <> "."
690692 , line "The error arises from the type"
691693 , markCodeBox $ indent $ typeAsBox ty
692694 , line "having the kind"
@@ -694,7 +696,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
694696 , line "instead."
695697 ]
696698 renderSimpleErrorMessage (IncorrectConstructorArity nm) =
697− line $ "Data constructor " ++ markCode (showQualified runProperName nm) ++ " was given the wrong number of arguments in a case expression."
699+ line $ "Data constructor " <> markCode (showQualified runProperName nm) <> " was given the wrong number of arguments in a case expression."
698700 renderSimpleErrorMessage (ExprDoesNotHaveType expr ty) =
699701 paras [ line "Expression"
700702 , markCodeBox $ indent $ prettyPrintValue valueDepth expr
@@ -702,13 +704,13 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
702704 , markCodeBox $ indent $ typeAsBox ty
703705 ]
704706 renderSimpleErrorMessage (PropertyIsMissing prop) =
705− line $ "Type of expression lacks required label " ++ markCode prop ++ "."
707+ line $ "Type of expression lacks required label " <> markCode prop <> "."
706708 renderSimpleErrorMessage (AdditionalProperty prop) =
707− line $ "Type of expression contains additional label " ++ markCode prop ++ "."
709+ line $ "Type of expression contains additional label " <> markCode prop <> "."
708710 renderSimpleErrorMessage TypeSynonymInstance =
709711 line "Type class instances for type synonyms are disallowed."
710712 renderSimpleErrorMessage (OrphanInstance nm cnm ts) =
711− paras [ line $ "Type class instance " ++ markCode (showIdent nm) ++ " for "
713+ paras [ line $ "Type class instance " <> markCode (showIdent nm) <> " for "
712714 , markCodeBox $ indent $ Box.hsep 1 Box.left
713715 [ line (showQualified runProperName cnm)
714716 , Box.vcat Box.left (map typeAtomAsBox ts)
@@ -718,7 +720,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
718720 , line "Consider moving the instance, if possible, or using a newtype wrapper."
719721 ]
720722 renderSimpleErrorMessage (InvalidNewtype name) =
721− paras [ line $ "Newtype " ++ markCode (runProperName name) ++ " is invalid."
723+ paras [ line $ "Newtype " <> markCode (runProperName name) <> " is invalid."
722724 , line "Newtypes must define a single constructor with a single argument."
723725 ]
724726 renderSimpleErrorMessage (InvalidInstanceHead ty) =
@@ -727,29 +729,29 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
727729 , line "All types appearing in instance declarations must be of the form T a_1 .. a_n, where each type a_i is of the same form."
728730 ]
729731 renderSimpleErrorMessage (TransitiveExportError x ys) =
730− paras [ line $ "An export for " ++ markCode (prettyPrintExport x) ++ " requires the following to also be exported: "
732+ paras [ line $ "An export for " <> markCode (prettyPrintExport x) <> " requires the following to also be exported: "
731733 , indent $ paras $ map (line . markCode . prettyPrintExport) ys
732734 ]
733735 renderSimpleErrorMessage (TransitiveDctorExportError x ctor) =
734− paras [ line $ "An export for " ++ markCode (prettyPrintExport x) ++ " requires the following data constructor to also be exported: "
736+ paras [ line $ "An export for " <> markCode (prettyPrintExport x) <> " requires the following data constructor to also be exported: "
735737 , indent $ line $ markCode $ runProperName ctor
736738 ]
737739 renderSimpleErrorMessage (ShadowedName nm) =
738− line $ "Name " ++ markCode (showIdent nm) ++ " was shadowed."
740+ line $ "Name " <> markCode (showIdent nm) <> " was shadowed."
739741 renderSimpleErrorMessage (ShadowedTypeVar tv) =
740− line $ "Type variable " ++ markCode tv ++ " was shadowed."
742+ line $ "Type variable " <> markCode tv <> " was shadowed."
741743 renderSimpleErrorMessage (UnusedTypeVar tv) =
742− line $ "Type variable " ++ markCode tv ++ " was declared but not used."
744+ line $ "Type variable " <> markCode tv <> " was declared but not used."
743745 renderSimpleErrorMessage (MisleadingEmptyTypeImport mn name) =
744− line $ "Importing type " ++ markCode (runProperName name ++ "(..)") ++ " from " ++ markCode (runModuleName mn) ++ " is misleading as it has no exported data constructors."
746+ line $ "Importing type " <> markCode (runProperName name <> "(..)") <> " from " <> markCode (runModuleName mn) <> " is misleading as it has no exported data constructors."
745747 renderSimpleErrorMessage (ImportHidingModule name) =
746748 paras [ line "hiding imports cannot be used to hide modules."
747− , line $ "An attempt was made to hide the import of " ++ markCode (runModuleName name)
749+ , line $ "An attempt was made to hide the import of " <> markCode (runModuleName name)
748750 ]
749751 renderSimpleErrorMessage (WildcardInferredType ty ctx) =
750752 paras $ [ line "Wildcard type definition has the inferred type "
751753 , markCodeBox $ indent $ typeAsBox ty
752− ] ++ renderContext ctx
754+ ] <> renderContext ctx
753755 renderSimpleErrorMessage (HoleInferredType name ty ctx ts) =
754756 let
755757 maxTSResults = 15
@@ -758,7 +760,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
758760 let
759761 formatTS (names, types) =
760762 let
761− idBoxes = Box.text . showQualified runIdent <$> names
763+ idBoxes = Box.text . T.unpack . showQualified runIdent <$> names
762764 tyBoxes = (\t -> BoxHelpers.indented
763765 (Box.text ":: " Box.<> typeAsBox t)) <$> types
764766 longestId = maximum (map Box.cols idBoxes)
@@ -772,13 +774,13 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
772774 ]
773775 _ -> []
774776 in
775− paras $ [ line $ "Hole '" ++ markCode name ++ "' has the inferred type "
777+ paras $ [ line $ "Hole '" <> markCode name <> "' has the inferred type "
776778 , markCodeBox (indent (typeAsBox ty))
777779 ] ++ tsResult ++ renderContext ctx
778780 renderSimpleErrorMessage (MissingTypeDeclaration ident ty) =
779− paras [ line $ "No type declaration was provided for the top-level declaration of " ++ markCode (showIdent ident) ++ "."
781+ paras [ line $ "No type declaration was provided for the top-level declaration of " <> markCode (showIdent ident) <> "."
780782 , line "It is good practice to provide type declarations as a form of documentation."
781− , line $ "The inferred type of " ++ markCode (showIdent ident) ++ " was:"
783+ , line $ "The inferred type of " <> markCode (showIdent ident) <> " was:"
782784 , markCodeBox $ indent $ typeAsBox ty
783785 ]
784786 renderSimpleErrorMessage (OverlappingPattern bs b) =
@@ -791,70 +793,70 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
791793 , line "You may want to decompose your data types into smaller types."
792794 ]
793795 renderSimpleErrorMessage (UnusedImport name) =
794− line $ "The import of module " ++ markCode (runModuleName name) ++ " is redundant"
796+ line $ "The import of module " <> markCode (runModuleName name) <> " is redundant"
795797
796798 renderSimpleErrorMessage msg@(UnusedExplicitImport mn names _ _) =
797− paras [ line $ "The import of module " ++ markCode (runModuleName mn) ++ " contains the following unused references:"
799+ paras [ line $ "The import of module " <> markCode (runModuleName mn) <> " contains the following unused references:"
798800 , indent $ paras $ map (line . markCode . runName . Qualified Nothing) names
799801 , line "It could be replaced with:"
800802 , indent $ line $ markCode $ showSuggestion msg ]
801803
802804 renderSimpleErrorMessage msg@(UnusedDctorImport mn name _ _) =
803− paras [line $ "The import of type " ++ markCode (runProperName name)
804− ++ " from module " ++ markCode (runModuleName mn) ++ " includes data constructors but only the type is used"
805+ paras [line $ "The import of type " <> markCode (runProperName name)
806+ <> " from module " <> markCode (runModuleName mn) <> " includes data constructors but only the type is used"
805807 , line "It could be replaced with:"
806808 , indent $ line $ markCode $ showSuggestion msg ]
807809
808810 renderSimpleErrorMessage msg@(UnusedDctorExplicitImport mn name names _ _) =
809− paras [ line $ "The import of type " ++ markCode (runProperName name)
810− ++ " from module " ++ markCode (runModuleName mn) ++ " includes the following unused data constructors:"
811+ paras [ line $ "The import of type " <> markCode (runProperName name)
812+ <> " from module " <> markCode (runModuleName mn) <> " includes the following unused data constructors:"
811813 , indent $ paras $ map (line . markCode . runProperName) names
812814 , line "It could be replaced with:"
813815 , indent $ line $ markCode $ showSuggestion msg ]
814816
815817 renderSimpleErrorMessage (DuplicateSelectiveImport name) =
816− line $ "There is an existing import of " ++ markCode (runModuleName name) ++ ", consider merging the import lists"
818+ line $ "There is an existing import of " <> markCode (runModuleName name) <> ", consider merging the import lists"
817819
818820 renderSimpleErrorMessage (DuplicateImport name imp qual) =
819− line $ "Duplicate import of " ++ markCode (prettyPrintImport name imp qual)
821+ line $ "Duplicate import of " <> markCode (prettyPrintImport name imp qual)
820822
821823 renderSimpleErrorMessage (DuplicateImportRef name) =
822− line $ "Import list contains multiple references to " ++ printName (Qualified Nothing name)
824+ line $ "Import list contains multiple references to " <> printName (Qualified Nothing name)
823825
824826 renderSimpleErrorMessage (DuplicateExportRef name) =
825− line $ "Export list contains multiple references to " ++ printName (Qualified Nothing name)
827+ line $ "Export list contains multiple references to " <> printName (Qualified Nothing name)
826828
827829 renderSimpleErrorMessage (IntOutOfRange value backend lo hi) =
828− paras [ line $ "Integer value " ++ markCode (show value) ++ " is out of range for the " ++ backend ++ " backend."
829− , line $ "Acceptable values fall within the range " ++ markCode (show lo) ++ " to " ++ markCode (show hi) ++ " (inclusive)." ]
830+ paras [ line $ "Integer value " <> markCode (T.pack (show value)) <> " is out of range for the " <> backend <> " backend."
831+ , line $ "Acceptable values fall within the range " <> markCode (T.pack (show lo)) <> " to " <> markCode (T.pack (show hi)) <> " (inclusive)." ]
830832
831833 renderSimpleErrorMessage msg@(ImplicitQualifiedImport importedModule asModule _) =
832− paras [ line $ "Module " ++ markCode (runModuleName importedModule) ++ " was imported as " ++ markCode (runModuleName asModule) ++ " with unspecified imports."
833− , line $ "As there are multiple modules being imported as " ++ markCode (runModuleName asModule) ++ ", consider using the explicit form:"
834+ paras [ line $ "Module " <> markCode (runModuleName importedModule) <> " was imported as " <> markCode (runModuleName asModule) <> " with unspecified imports."
835+ , line $ "As there are multiple modules being imported as " <> markCode (runModuleName asModule) <> ", consider using the explicit form:"
834836 , indent $ line $ markCode $ showSuggestion msg
835837 ]
836838
837839 renderSimpleErrorMessage msg@(ImplicitImport mn _) =
838− paras [ line $ "Module " ++ markCode (runModuleName mn) ++ " has unspecified imports, consider using the explicit form: "
840+ paras [ line $ "Module " <> markCode (runModuleName mn) <> " has unspecified imports, consider using the explicit form: "
839841 , indent $ line $ markCode $ showSuggestion msg
840842 ]
841843
842844 renderSimpleErrorMessage msg@(HidingImport mn _) =
843− paras [ line $ "Module " ++ markCode (runModuleName mn) ++ " has unspecified imports, consider using the inclusive form: "
845+ paras [ line $ "Module " <> markCode (runModuleName mn) <> " has unspecified imports, consider using the inclusive form: "
844846 , indent $ line $ markCode $ showSuggestion msg
845847 ]
846848
847849 renderSimpleErrorMessage (CaseBinderLengthDiffers l bs) =
848850 paras [ line "Binder list length differs in case alternative:"
849− , indent $ line $ intercalate ", " $ fmap prettyPrintBinderAtom bs
850− , line $ "Expecting " ++ show l ++ " binder" ++ (if l == 1 then "" else "s") ++ "."
851+ , indent $ line $ T.intercalate ", " $ fmap prettyPrintBinderAtom bs
852+ , line $ "Expecting " <> T.pack (show l) <> " binder" <> (if l == 1 then "" else "s") <> "."
851853 ]
852854
853855 renderSimpleErrorMessage IncorrectAnonymousArgument =
854856 line "An anonymous function argument appears in an invalid context."
855857
856858 renderSimpleErrorMessage (InvalidOperatorInBinder op fn) =
857− paras [ line $ "Operator " ++ markCode (showQualified showOp op) ++ " cannot be used in a pattern as it is an alias for function " ++ showQualified showIdent fn ++ "."
859+ paras [ line $ "Operator " <> markCode (showQualified showOp op) <> " cannot be used in a pattern as it is an alias for function " <> showQualified showIdent fn <> "."
858860 , line "Only aliases for data constructors may be used in patterns."
859861 ]
860862
@@ -862,18 +864,18 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
862864 line "The require-path option is deprecated and will be removed in PureScript 0.9."
863865
864866 renderSimpleErrorMessage (CannotGeneralizeRecursiveFunction ident ty) =
865− paras [ line $ "Unable to generalize the type of the recursive function " ++ markCode (showIdent ident) ++ "."
866− , line $ "The inferred type of " ++ markCode (showIdent ident) ++ " was:"
867+ paras [ line $ "Unable to generalize the type of the recursive function " <> markCode (showIdent ident) <> "."
868+ , line $ "The inferred type of " <> markCode (showIdent ident) <> " was:"
867869 , markCodeBox $ indent $ typeAsBox ty
868870 , line "Try adding a type signature."
869871 ]
870872
871873 renderSimpleErrorMessage (CannotDeriveNewtypeForData tyName) =
872− paras [ line $ "Cannot derive an instance of the " ++ markCode "Newtype" ++ " class for non-newtype " ++ markCode (runProperName tyName) ++ "."
874+ paras [ line $ "Cannot derive an instance of the " <> markCode "Newtype" <> " class for non-newtype " <> markCode (runProperName tyName) <> "."
873875 ]
874876
875877 renderSimpleErrorMessage (ExpectedWildcard tyName) =
876− paras [ line $ "Expected a type wildcard (_) when deriving an instance for " ++ markCode (runProperName tyName) ++ "."
878+ paras [ line $ "Expected a type wildcard (_) when deriving an instance for " <> markCode (runProperName tyName) <> "."
877879 ]
878880
879881 renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
@@ -893,7 +895,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
893895 ]
894896 ]
895897 renderHint (ErrorInModule mn) detail =
896− paras [ line $ "in module " ++ markCode (runModuleName mn)
898+ paras [ line $ "in module " <> markCode (runModuleName mn)
897899 , detail
898900 ]
899901 renderHint (ErrorInSubsumption t1 t2) detail =
@@ -958,15 +960,15 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
958960 ]
959961 renderHint (ErrorInDataConstructor nm) detail =
960962 paras [ detail
961− , line $ "in data constructor " ++ markCode (runProperName nm)
963+ , line $ "in data constructor " <> markCode (runProperName nm)
962964 ]
963965 renderHint (ErrorInTypeConstructor nm) detail =
964966 paras [ detail
965− , line $ "in type constructor " ++ markCode (runProperName nm)
967+ , line $ "in type constructor " <> markCode (runProperName nm)
966968 ]
967969 renderHint (ErrorInBindingGroup nms) detail =
968970 paras [ detail
969− , line $ "in binding group " ++ intercalate ", " (map showIdent nms)
971+ , line $ "in binding group " <> T.intercalate ", " (map showIdent nms)
970972 ]
971973 renderHint (ErrorInDataBindingGroup nms) detail =
972974 paras [ detail
@@ -974,15 +976,15 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
974976 ]
975977 renderHint (ErrorInTypeSynonym name) detail =
976978 paras [ detail
977− , line $ "in type synonym " ++ markCode (runProperName name)
979+ , line $ "in type synonym " <> markCode (runProperName name)
978980 ]
979981 renderHint (ErrorInValueDeclaration n) detail =
980982 paras [ detail
981− , line $ "in value declaration " ++ markCode (showIdent n)
983+ , line $ "in value declaration " <> markCode (showIdent n)
982984 ]
983985 renderHint (ErrorInTypeDeclaration n) detail =
984986 paras [ detail
985− , line $ "in type declaration for " ++ markCode (showIdent n)
987+ , line $ "in type declaration for " <> markCode (showIdent n)
986988 ]
987989 renderHint (ErrorInTypeClassDeclaration name) detail =
988990 paras [ detail
@@ -990,7 +992,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
990992 ]
991993 renderHint (ErrorInForeignImport nm) detail =
992994 paras [ detail
993− , line $ "in foreign import " ++ markCode (showIdent nm)
995+ , line $ "in foreign import " <> markCode (showIdent nm)
994996 ]
995997 renderHint (ErrorSolvingConstraint (Constraint nm ts _)) detail =
996998 paras [ detail
@@ -1001,7 +1003,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
10011003 ]
10021004 ]
10031005 renderHint (PositionedError srcSpan) detail =
1004− paras [ line $ "at " ++ displaySourceSpan srcSpan
1006+ paras [ line $ "at " <> displaySourceSpan srcSpan
10051007 , detail
10061008 ]
10071009
@@ -1010,17 +1012,17 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
10101012 renderContext ctx =
10111013 [ line "in the following context:"
10121014 , indent $ paras
1013− [ Box.hcat Box.left [ Box.text (showIdent ident <> " :: ")
1015+ [ Box.hcat Box.left [ Box.text (T.unpack (showIdent ident) ++ " :: ")
10141016 , markCodeBox $ typeAsBox ty'
10151017 ]
10161018 | (ident, ty') <- take 5 ctx
10171019 ]
10181020 ]
10191021
1020− printName :: Qualified Name -> String
1021− printName qn = nameType (disqualify qn) ++ " " ++ markCode (runName qn)
1022+ printName :: Qualified Name -> Text
1023+ printName qn = nameType (disqualify qn) <> " " <> markCode (runName qn)
10221024
1023− nameType :: Name -> String
1025+ nameType :: Name -> Text
10241026 nameType (IdentName _) = "value"
10251027 nameType (ValOpName _) = "operator"
10261028 nameType (TyName _) = "type"
@@ -1029,7 +1031,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
10291031 nameType (TyClassName _) = "type class"
10301032 nameType (ModName _) = "module"
10311033
1032− runName :: Qualified Name -> String
1034+ runName :: Qualified Name -> Text
10331035 runName (Qualified mn (IdentName name)) =
10341036 showQualified showIdent (Qualified mn name)
10351037 runName (Qualified mn (ValOpName op)) =
@@ -1051,7 +1053,7 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
10511053 valueDepth | full = 1000
10521054 | otherwise = 3
10531055
1054− levelText :: String
1056+ levelText :: Text
10551057 levelText = case level of
10561058 Error -> "error"
10571059 Warning -> "warning"
@@ -1112,40 +1114,40 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
11121114 hintCategory _ = OtherHint
11131115
11141116-- Pretty print and export declaration
1115−prettyPrintExport :: DeclarationRef -> String
1117+prettyPrintExport :: DeclarationRef -> Text
11161118prettyPrintExport (TypeRef pn _) = runProperName pn
11171119prettyPrintExport ref =
11181120 fromMaybe
11191121 (internalError "prettyPrintRef returned Nothing in prettyPrintExport")
11201122 (prettyPrintRef ref)
11211123
1122−prettyPrintImport :: ModuleName -> ImportDeclarationType -> Maybe ModuleName -> String
1124+prettyPrintImport :: ModuleName -> ImportDeclarationType -> Maybe ModuleName -> Text
11231125prettyPrintImport mn idt qual =
11241126 let i = case idt of
11251127 Implicit -> runModuleName mn
1126− Explicit refs -> runModuleName mn ++ " (" ++ intercalate ", " (mapMaybe prettyPrintRef refs) ++ ")"
1127− Hiding refs -> runModuleName mn ++ " hiding (" ++ intercalate "," (mapMaybe prettyPrintRef refs) ++ ")"
1128− in i ++ maybe "" (\q -> " as " ++ runModuleName q) qual
1128+ Explicit refs -> runModuleName mn <> " (" <> T.intercalate ", " (mapMaybe prettyPrintRef refs) <> ")"
1129+ Hiding refs -> runModuleName mn <> " hiding (" <> T.intercalate "," (mapMaybe prettyPrintRef refs) <> ")"
1130+ in i <> maybe "" (\q -> " as " <> runModuleName q) qual
11291131
1130−prettyPrintRef :: DeclarationRef -> Maybe String
1132+prettyPrintRef :: DeclarationRef -> Maybe Text
11311133prettyPrintRef (TypeRef pn Nothing) =
1132− Just $ runProperName pn ++ "(..)"
1134+ Just $ runProperName pn <> "(..)"
11331135prettyPrintRef (TypeRef pn (Just [])) =
11341136 Just $ runProperName pn
11351137prettyPrintRef (TypeRef pn (Just dctors)) =
1136− Just $ runProperName pn ++ "(" ++ intercalate ", " (map runProperName dctors) ++ ")"
1138+ Just $ runProperName pn <> "(" <> T.intercalate ", " (map runProperName dctors) <> ")"
11371139prettyPrintRef (TypeOpRef op) =
1138− Just $ "type " ++ showOp op
1140+ Just $ "type " <> showOp op
11391141prettyPrintRef (ValueRef ident) =
11401142 Just $ showIdent ident
11411143prettyPrintRef (ValueOpRef op) =
11421144 Just $ showOp op
11431145prettyPrintRef (TypeClassRef pn) =
1144− Just $ "class " ++ runProperName pn
1146+ Just $ "class " <> runProperName pn
11451147prettyPrintRef (TypeInstanceRef ident) =
11461148 Just $ showIdent ident
11471149prettyPrintRef (ModuleRef name) =
1148− Just $ "module " ++ runModuleName name
1150+ Just $ "module " <> runModuleName name
11491151prettyPrintRef (ReExportRef _ _) =
11501152 Nothing
11511153prettyPrintRef (PositionedDeclarationRef _ _ ref) =
@@ -1238,8 +1240,11 @@ prettyPrintParseErrorMessages msgOr msgUnknown msgExpecting msgUnExpected msgEnd
12381240indent :: Box.Box -> Box.Box
12391241indent = Box.moveUp 1 . Box.moveDown 1 . Box.moveRight 2
12401242
1241−line :: String -> Box.Box
1242−line = Box.text
1243+line :: Text -> Box.Box
1244+line = Box.text . T.unpack
1245+
1246+lineS :: String -> Box.Box
1247+lineS = Box.text
12431248
12441249renderBox :: Box.Box -> String
12451250renderBox = unlines
@@ -1253,7 +1258,7 @@ renderBox = unlines
12531258 whiteSpace = all isSpace
12541259
12551260toTypelevelString :: Type -> Maybe Box.Box
1256−toTypelevelString (TypeLevelString s) = Just $ Box.text s
1261+toTypelevelString (TypeLevelString s) = Just $ Box.text (T.unpack s)
12571262toTypelevelString (TypeApp (TypeConstructor f) x)
12581263 | f == primName "TypeString" = Just $ typeAsBox x
12591264toTypelevelString (TypeApp (TypeApp (TypeConstructor f) x) ret)