on master help sign in
Update a bunch of files based on Doc changes
commitb1fd35f5f22a002349ac14b6b8082aee98a6a9e5 authorEvan Czaplicki <evancz@users.noreply.github.com> dateSat 7 Apr 2018, 19:55 (9 years ago) parent31e51c1
22 files changed+761−780
builder/src/Deps/Get.hs+3−3 builder/src/Elm/Project/Licenses.hs+2−2 builder/src/Reporting/Exit.hs+4−6 compiler/src/Elm/Compiler.hs+5−10 compiler/src/Elm/Compiler/Type.hs+24−24 compiler/src/Elm/Utils.hs−14 compiler/src/Generate/JavaScript.hs+4−5 compiler/src/Json/Decode.hs+2−2 compiler/src/Json/Decode/Error.hs+27−27 compiler/src/Reporting/Error/Canonicalize.hs+205−204 compiler/src/Reporting/Error/Docs.hs+24−24 compiler/src/Reporting/Error/Main.hs+16−16 compiler/src/Reporting/Error/Pattern.hs+21−21 compiler/src/Reporting/Error/Syntax.hs+65−65 compiler/src/Reporting/Error/Type.hs+251−251 compiler/src/Reporting/Render/Code.hs+15−17 compiler/src/Reporting/Render/Type.hs+25−25 compiler/src/Reporting/Warning.hs+10−10 compiler/src/Type/Error.hs+45−45 elm.cabal+4−4 ui/terminal/src/Repl.hs+1−1 ui/terminal/src/Terminal/Args/Error.hs+8−4
builder/src/Deps/Get.hs+3−3
@@ -25,11 +25,11 @@ import qualified Text.PrettyPrint.ANSI.Leijen as P
2525
2626import qualified Elm.Docs as Docs
2727import qualified Elm.Package as Pkg
28−import qualified Elm.Utils as Utils
2928
3029import qualified Deps.Website as Website
3130import qualified Elm.Project.Json as Project
3231import qualified File.IO as IO
32+import qualified Reporting.Suggest as Suggest
3333import qualified Reporting.Exit as Exit
3434import qualified Reporting.Exit.Assets as E
3535import qualified Reporting.Progress as Progress
@@ -122,7 +122,7 @@ nearbyNames (Pkg.Name author1 project1) possibleNames =
122122
123123authorDistance :: String -> Text.Text -> Int
124124authorDistance bad possibility =
125− abs (Utils.distance bad (Text.unpack possibility))
125+ abs (Suggest.distance bad (Text.unpack possibility))
126126
127127
128128projectDistance :: String -> Text.Text -> Int
@@ -130,7 +130,7 @@ projectDistance bad possibility =
130130 if possibility == "elm-lang" || possibility == "elm-explorations" then
131131 0
132132 else
133− abs (Utils.distance bad (Text.unpack possibility))
133+ abs (Suggest.distance bad (Text.unpack possibility))
134134
135135
136136
builder/src/Elm/Project/Licenses.hs+2−2
@@ -13,8 +13,8 @@ import Data.Map ((!))
1313import qualified Data.Map as Map
1414import qualified Data.Text as Text
1515
16−import qualified Elm.Utils as Utils
1716import qualified Json.Encode as Encode
17+import qualified Reporting.Suggest as Suggest
1818
1919
2020
@@ -61,7 +61,7 @@ check rawName =
6161 Text.unpack suggestion
6262 in
6363 Left $ map snd $
64− Utils.nearbyNames toSuggestion (rawName, rawName) pairs
64+ Suggest.nearbyNames toSuggestion (rawName, rawName) pairs
6565
6666
6767
builder/src/Reporting/Exit.hs+4−6
@@ -8,16 +8,14 @@ module Reporting.Exit
88 where
99
1010
11−import qualified Data.ByteString.Builder as B
1211import Data.Monoid ((<>))
13−import System.IO (stderr)
1412import qualified Text.PrettyPrint.ANSI.Leijen as P
1513
1614import qualified Elm.Compiler as Compiler
1715import qualified Elm.Compiler.Module as Module
1816import qualified Elm.Package as Pkg
19−import qualified Elm.Utils as Utils
2017import qualified Json.Encode as Encode
18+import qualified Reporting.Doc as D
2119import qualified Reporting.Exit.Assets as Asset
2220import qualified Reporting.Exit.Bump as Bump
2321import qualified Reporting.Exit.Compile as Compile
@@ -65,9 +63,9 @@ toStderr exit =
6563 Help.toStderr (Help.reportToDoc (toReport exit))
6664
6765
68−toJson :: Exit -> IO ()
66+toJson :: Exit -> Encode.Value
6967toJson exit =
70− B.hPutBuilder stderr $ Encode.encodeUgly $ Help.reportToJson (toReport exit)
68+ Help.reportToJson (toReport exit)
7169
7270
7371toReport :: Exit -> Help.Report
@@ -106,7 +104,7 @@ toReport exit =
106104 Cycle names ->
107105 Help.report "IMPORT CYCLE" Nothing
108106 "Your module imports form a cycle:"
109− [ P.indent 4 (Utils.drawCycle names)
107+ [ D.cycle 4 names
110108 , Help.reflow $
111109 "Learn more about why this is disallowed and how to break cycles here:"
112110 ++ Help.hintLink "import-cycles"
compiler/src/Elm/Compiler.hs+5−10
@@ -16,15 +16,14 @@ module Elm.Compiler
1616import qualified Data.ByteString as BS
1717import qualified Data.Map as Map
1818import qualified Data.Text as Text
19−import qualified Text.PrettyPrint.ANSI.Leijen as P
2019
2120import qualified Compile
2221import qualified Elm.Compiler.Module as M
2322import qualified Elm.Compiler.Version
2423import qualified Elm.Package as Pkg
2524import qualified Json.Encode as Encode
25+import qualified Reporting.Doc as D
2626import qualified Reporting.Error as Error
27−import qualified Reporting.Helpers as H
2827import qualified Reporting.Render.Code as Code
2928import qualified Reporting.Region as Region
3029import qualified Reporting.Report as Report
@@ -63,13 +62,13 @@ compile (Context pkg docsFlag importDict interfaces) source =
6362-- ERRORS TO DOC
6463
6564
66−errorsToDoc :: FilePath -> Text.Text -> [Error.Error] -> H.Doc
65+errorsToDoc :: FilePath -> Text.Text -> [Error.Error] -> D.Doc
6766errorsToDoc filePath source errors =
6867 let
6968 reports =
7069 concatMap (Error.toReports (Code.toSource source) Map.empty) errors
7170 in
72− H.vcat $ map (Report.toDoc filePath) reports
71+ D.vcat $ map (Report.toDoc filePath) reports
7372
7473
7574
@@ -85,18 +84,14 @@ errorsToJson moduleName filePath source errors =
8584 Encode.object
8685 [ ("path", Encode.text (Text.pack filePath))
8786 , ("name", Encode.name moduleName)
88− , ("errors", Encode.array (map reportToJson reports))
87+ , ("problems", Encode.array (map reportToJson reports))
8988 ]
9089
9190
9291reportToJson :: Report.Report -> Encode.Value
9392reportToJson (Report.Report title region _sgstns message) =
94− let
95− messageString =
96− P.displayS (P.renderPretty 1 80 message) ""
97− in
9893 Encode.object
9994 [ ("title", Encode.text (Text.pack title))
10095 , ("region", Region.encode region)
101− , ("message", Encode.text (Text.pack messageString))
96+ , ("message", D.encode message)
10297 ]
compiler/src/Elm/Compiler/Type.hs+24−24
@@ -16,14 +16,14 @@ module Elm.Compiler.Type
1616
1717import qualified Data.Text as Text
1818import qualified Data.Text.Encoding as Text
19−import qualified Text.PrettyPrint.ANSI.Leijen as P
20−import Text.PrettyPrint.ANSI.Leijen ((<+>))
2119
2220import qualified AST.Source as Src
2321import qualified Elm.Name as N
2422import qualified Parse.Primitives as Parse
2523import qualified Parse.Type as Type
2624import qualified Reporting.Annotation as A
25+import qualified Reporting.Doc as D
26+import Reporting.Doc ((<>), (<+>))
2727import qualified Json.Decode as Decode
2828import qualified Json.Encode as Encode
2929import Json.Encode ((==>))
@@ -61,7 +61,7 @@ data Union = Union N.Name [N.Name] [(N.Name, [Type])]
6161data Context = None | InType | InFunction
6262
6363
64−toDoc :: Context -> Type -> P.Doc
64+toDoc :: Context -> Type -> D.Doc
6565toDoc context tipe =
6666 case tipe of
6767 Lambda _ _ ->
@@ -69,21 +69,21 @@ toDoc context tipe =
6969 map (toDoc InFunction) (collectLambdas tipe)
7070
7171 lambda =
72− P.sep [ t, P.sep (map (P.text "->" <+>) ts) ]
72+ D.sep [ t, D.sep (map ("->" <+>) ts) ]
7373 in
7474 case context of
7575 None -> lambda
76− _ -> P.parens lambda
76+ _ -> "(" <> lambda <> ")"
7777
7878 Var name ->
79− P.text (N.toString name)
79+ D.fromName name
8080
8181 Unit ->
8282 "()"
8383
8484 Tuple a b cs ->
85− P.sep
86− [ P.cat $
85+ D.sep
86+ [ D.cat $
8787 [ "(" <+> toDoc None a
8888 , "," <+> toDoc None b
8989 ]
@@ -94,19 +94,19 @@ toDoc context tipe =
9494 Type name args ->
9595 case args of
9696 [] ->
97− P.text (N.toString name)
97+ D.fromName name
9898
9999 _ ->
100100 let
101101 docName =
102− P.text (N.toString name)
102+ D.fromName name
103103
104104 application =
105− P.hang 2 $ P.sep (docName : map (toDoc InType) args)
105+ D.hang 2 $ D.sep (docName : map (toDoc InType) args)
106106 in
107107 case context of
108108 InType ->
109− P.parens application
109+ "(" <> application <> ")"
110110
111111 _ ->
112112 application
@@ -117,23 +117,24 @@ toDoc context tipe =
117117 Record fields ext ->
118118 case ext of
119119 Nothing ->
120− P.sep
121− [ P.cat (zipWith (<+>) ("{" : repeat ",") (map entryToDoc fields))
120+ D.sep
121+ [ D.cat (zipWith (<+>) ("{" : repeat ",") (map entryToDoc fields))
122122 , "}"
123123 ]
124124
125125 Just x ->
126− P.hang 4 $
127− P.sep
128− [ "{" <+> P.text (N.toString x) <+> "|"
129− , P.sep (P.punctuate "," (map entryToDoc fields))
130− , "}"
131− ]
126+ D.sep
127+ [ D.hang 4 $ D.sep $
128+ [ "{" <+> D.fromName x
129+ , D.cat (zipWith (<+>) ("|" : repeat ",") (map entryToDoc fields))
130+ ]
131+ , "}"
132+ ]
132133
133134
134−entryToDoc :: (N.Name, Type) -> P.Doc
135+entryToDoc :: (N.Name, Type) -> D.Doc
135136entryToDoc (field, fieldType) =
136− P.text (N.toString field) <+> ":" <+> toDoc None fieldType
137+ D.fromName field <+> ":" <+> toDoc None fieldType
137138
138139
139140collectLambdas :: Type -> [Type]
@@ -149,8 +150,7 @@ collectLambdas tipe =
149150
150151encode :: Type -> Encode.Value
151152encode tipe =
152− Encode.text $ Text.pack $
153− P.displayS (P.renderPretty 1.0 (maxBound `div` 2) (toDoc None tipe)) ""
153+ Encode.text $ Text.pack $ D.toLine (toDoc None tipe)
154154
155155
156156decoder :: Decode.Decoder () Type
compiler/src/Elm/Utils.hsdeleted−14
@@ -1,14 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−module Elm.Utils
3− ( drawCycle
4− , nearbyNames
5− , distance
6− , Entry(..)
7− , parseEntry
8− )
9− where
10−
11−
12−import Parse.Repl (Entry(..), parseEntry)
13−import Reporting.Helpers (drawCycle, nearbyNames, distance)
14−
compiler/src/Generate/JavaScript.hs+4−5
@@ -17,7 +17,6 @@ import qualified Data.Map as Map
1717import qualified Data.Set as Set
1818import qualified Data.Text as Text
1919import qualified Data.Text.Encoding as Text
20−import qualified Text.PrettyPrint.ANSI.Leijen as P
2120
2221import qualified AST.Canonical as Can
2322import qualified AST.Optimized as Opt
@@ -30,7 +29,7 @@ import qualified Elm.Name as N
3029import qualified Generate.JavaScript.Builder as JS
3130import qualified Generate.JavaScript.Expression as Expr
3231import qualified Generate.JavaScript.Name as Name
33−import qualified Reporting.Helpers as H
32+import qualified Reporting.Doc as D
3433
3534
3635
@@ -98,10 +97,10 @@ print home name annotation =
9897 let
9998 value = Name.toBuilder (Name.fromGlobal home name)
10099 toString = Name.toBuilder (Name.fromKernel N.debug "toString")
101− tipe = P.displayS (P.renderPretty 1.0 80 (Type.toDoc Type.None (Extract.fromAnnotation annotation))) ""
100+ tipe = Type.toDoc Type.None (Extract.fromAnnotation annotation)
102101 in
103102 "var _value = " <> toString <> "(" <> value <> ");\n" <>
104− "var _type = " <> B.stringUtf8 (show tipe) <> ";\n\
103+ "var _type = " <> B.stringUtf8 (show (D.toString tipe)) <> ";\n\
105104 \if (_value.length + 3 + _type.length >= 80 || _type.indexOf('\\n') >= 0) {\n\
106105 \ console.log(_value + '\\n : ' + _type.split('\\n').join('\\n '));\n\
107106 \} else {\n\
@@ -244,7 +243,7 @@ generateCycle mode (Opt.Global home _) cycle =
244243 "The following top-level definitions are causing infinite recursion:\\n"
245244 <> drawCycle (map fst cycle)
246245 <> "\\n\\nThese errors are very tricky, so read "
247− <> B.stringUtf8 (H.makeLink "halting-problem")
246+ <> B.stringUtf8 (D.makeLink "halting-problem")
248247 <> " to learn how to fix it!"
249248
250249
compiler/src/Json/Decode.hs+2−2
@@ -33,8 +33,8 @@ import Parse.Primitives.Internals (Parser(..), State(..), noError)
3333import qualified Parse.Primitives.Keyword as Keyword
3434import qualified Parse.Primitives.Number as Number
3535import qualified Parse.Primitives.Symbol as Symbol
36+import qualified Reporting.Doc as D
3637import qualified Reporting.Error.Syntax as E
37−import qualified Reporting.Helpers as H
3838import qualified Reporting.Region as R
3939import qualified Reporting.Render.Code as Code
4040
@@ -43,7 +43,7 @@ import qualified Reporting.Render.Code as Code
4343-- PARSE
4444
4545
46−parse :: String -> (e -> [H.Doc]) -> Json.Decoder e a -> B.ByteString -> Either H.Doc a
46+parse :: String -> (e -> [D.Doc]) -> Json.Decoder e a -> B.ByteString -> Either D.Doc a
4747parse rootName userErrorToDocs (Json.Decoder run) bytestring =
4848 let
4949 source =
compiler/src/Json/Decode/Error.hs+27−27
@@ -16,8 +16,8 @@ import qualified Text.PrettyPrint.ANSI.Leijen as P
1616
1717import qualified Json.Decode.Internals as Json
1818import qualified Json.Encode as E
19+import qualified Reporting.Doc as D
1920import qualified Reporting.Error.Syntax as Syntax
20−import qualified Reporting.Helpers as H
2121import qualified Reporting.Render.Code as Code
2222import qualified Reporting.Report as Report
2323
@@ -35,7 +35,7 @@ data Error e
3535-- TO DOC
3636
3737
38−toDoc :: String -> Code.Source -> (e -> [H.Doc]) -> Error e -> H.Doc
38+toDoc :: String -> Code.Source -> (e -> [D.Doc]) -> Error e -> D.Doc
3939toDoc rootName source userErrorToDocs err =
4040 case err of
4141 BadJson syntaxError ->
@@ -46,7 +46,7 @@ toDoc rootName source userErrorToDocs err =
4646 BadContent jsonError ->
4747 case flatten jsonError of
4848 [] ->
49− H.reflow
49+ D.reflow
5050 "I am not sure what is wrong with this JSON. Please create an <http://sscce.org>\
5151 \ and share it at <https://github.com/elm-lang/elm-compiler/issues> so I can\
5252 \ provide a helpful hint here!"
@@ -59,8 +59,8 @@ toDoc rootName source userErrorToDocs err =
5959 toNumberedDoc index flatErr =
6060 P.dullcyan ("(" <> P.int index <> ")") <+> flatErrorToDoc rootName [] userErrorToDocs flatErr
6161 in
62− H.stack $
63− [ H.reflow $
62+ D.stack $
63+ [ D.reflow $
6464 "I have " ++ show (length flatErrors) ++ " theories on what is going wrong:"
6565 ]
6666 ++ zipWith toNumberedDoc [1..] flatErrors
@@ -70,7 +70,7 @@ toDoc rootName source userErrorToDocs err =
7070-- FLAT ERROR TO DOC
7171
7272
73−flatErrorToDoc :: String -> [H.Doc] -> (e -> [H.Doc]) -> FlatError e -> H.Doc
73+flatErrorToDoc :: String -> [D.Doc] -> (e -> [D.Doc]) -> FlatError e -> D.Doc
7474flatErrorToDoc rootName starter userErrorToDocs (FlatError accesses json theory theories) =
7575 case theories of
7676 [] ->
@@ -85,12 +85,12 @@ flatErrorToDoc rootName starter userErrorToDocs (FlatError accesses json theory
8585 in
8686 case accesses of
8787 [] ->
88− H.fillSep (starter ++ explanation)
88+ D.fillSep (starter ++ explanation)
8989
9090 _ ->
91− H.stack
92− [ H.fillSep $ starter ++ ["The"] ++ actualThing json ++ ["at",accessToDoc rootName accesses,"is","causing","issues."]
93− , H.fillSep explanation
91+ D.stack
92+ [ D.fillSep $ starter ++ ["The"] ++ actualThing json ++ ["at",accessToDoc rootName accesses,"is","causing","issues."]
93+ , D.fillSep explanation
9494 ]
9595
9696 _:_ ->
@@ -107,31 +107,31 @@ flatErrorToDoc rootName starter userErrorToDocs (FlatError accesses json theory
107107 ++ actualThing json
108108 ++ ["at",accessToDoc rootName accesses,"because:"]
109109 in
110− H.stack
111− [ H.fillSep (starter ++ introduction)
112− , H.stack (toBullet [] userErrorToDocs theory : map (toBullet ["OR"] userErrorToDocs) theories)
113− , H.reflow "I accept any of these things."
110+ D.stack
111+ [ D.fillSep (starter ++ introduction)
112+ , D.stack (toBullet [] userErrorToDocs theory : map (toBullet ["OR"] userErrorToDocs) theories)
113+ , D.reflow "I accept any of these things."
114114 ]
115115
116116
117−accessToDoc :: String -> [String] -> H.Doc
117+accessToDoc :: String -> [String] -> D.Doc
118118accessToDoc rootName accesses =
119119 P.dullyellow (P.text (rootName ++ concat accesses))
120120
121121
122−actualThing :: E.Value -> [H.Doc]
122+actualThing :: E.Value -> [D.Doc]
123123actualThing json =
124124 case json of
125− E.Array _ -> [H.red "array"]
126− E.Object _ -> [H.red "object"]
127− E.String _ -> [H.red "string"]
128− E.Boolean b -> [H.red (if b then "true" else "false"),"value"]
129− E.Integer n -> ["number",H.red (H.text (show n))]
130− E.Number _ -> [H.red "number"]
131− E.Null -> [H.red "null","value"]
125+ E.Array _ -> [D.red "array"]
126+ E.Object _ -> [D.red "object"]
127+ E.String _ -> [D.red "string"]
128+ E.Boolean b -> [D.red (if b then "true" else "false"),"value"]
129+ E.Integer n -> ["number",D.red (D.fromString (show n))]
130+ E.Number _ -> [D.red "number"]
131+ E.Null -> [D.red "null","value"]
132132
133133
134−anExpectedThing :: Json.Type -> [H.Doc]
134+anExpectedThing :: Json.Type -> [D.Doc]
135135anExpectedThing tipe =
136136 case tipe of
137137 Json.TObject -> ["an", P.green "OBJECT" <> "."]
@@ -141,15 +141,15 @@ anExpectedThing tipe =
141141 Json.TInt -> ["an", P.green "INT" <> "."]
142142 Json.TObjectWith field -> ["an",P.green "OBJECT","with","a",P.green ("\"" <> P.text (Text.unpack field) <> "\""),"field."]
143143 Json.TArrayWith i len ->
144− ["a",H.green "longer",P.green "ARRAY" <> "."
144+ ["a",D.green "longer",P.green "ARRAY" <> "."
145145 ,"I","need","index",P.text (show i) <> ",","but","this","array"
146146 ,"only","has",P.text (show len),"elements."
147147 ]
148148
149149
150−toBullet :: [H.Doc] -> (e -> [H.Doc]) -> Theory e -> H.Doc
150+toBullet :: [D.Doc] -> (e -> [D.Doc]) -> Theory e -> D.Doc
151151toBullet intro userErrorToDocs theory =
152− H.indent 4 $ H.fillSep $ (++) intro $
152+ D.indent 4 $ D.fillSep $ (++) intro $
153153 case theory of
154154 Failure userError ->
155155 userErrorToDocs userError
compiler/src/Reporting/Error/Canonicalize.hs+205−204
@@ -23,12 +23,13 @@ import qualified AST.Module.Name as ModuleName
2323import qualified Data.Index as Index
2424import qualified Elm.Name as N
2525import qualified Reporting.Annotation as A
26+import qualified Reporting.Doc as D
27+import Reporting.Doc (Doc, (<+>), (<>))
2628import qualified Reporting.Region as R
2729import qualified Reporting.Render.Code as Code
2830import qualified Reporting.Render.Type as RT
2931import qualified Reporting.Report as Report
30−import qualified Reporting.Helpers as H
31−import Reporting.Helpers ( Doc, (<+>), (<>) )
32+import qualified Reporting.Suggest as Suggest
3233
3334
3435
@@ -126,16 +127,16 @@ toKindInfo :: VarKind -> N.Name -> ( Doc, Doc, Doc )
126127toKindInfo kind name =
127128 case kind of
128129 BadOp ->
129− ( "an", "operator", "(" <> H.nameToDoc name <> ")" )
130+ ( "an", "operator", "(" <> D.fromName name <> ")" )
130131
131132 BadVar ->
132− ( "a", "value", "`" <> H.nameToDoc name <> "`" )
133+ ( "a", "value", "`" <> D.fromName name <> "`" )
133134
134135 BadPattern ->
135− ( "a", "pattern", "`" <> H.nameToDoc name <> "`" )
136+ ( "a", "pattern", "`" <> D.fromName name <> "`" )
136137
137138 BadType ->
138− ( "a", "type", "`" <> H.nameToDoc name <> "`" )
139+ ( "a", "type", "`" <> D.fromName name <> "`" )
139140
140141
141142
@@ -153,12 +154,12 @@ toReport source err =
153154 Report.Report "BAD TYPE ANNOTATION" region [] $
154155 Report.toCodeSnippet source region Nothing
155156 (
156− H.reflow $
157+ D.reflow $
157158 "The type annotation for `" <> N.toString name <> "` says it can accept "
158− <> H.args numTypeArgs <> ", but the definition says it has "
159− <> H.args numDefArgs <> ":"
159+ <> D.args numTypeArgs <> ", but the definition says it has "
160+ <> D.args numDefArgs <> ":"
160161 ,
161− H.reflow $
162+ D.reflow $
162163 "Is the type annotation missing something? Should some argument"
163164 <> (if leftovers == 1 then "" else "s")
164165 <> " be deleted? Maybe some parentheses are missing?"
@@ -187,20 +188,20 @@ toReport source err =
187188 Report.Report "TOO FEW ARGS" region [] $
188189 Report.toCodeSnippet source region Nothing
189190 (
190− H.reflow $
191− "The `" <> N.toString name <> "` " <> thing <> " was given " <> H.args actual <> ":"
191+ D.reflow $
192+ "The `" <> N.toString name <> "` " <> thing <> " was given " <> D.args actual <> ":"
192193 ,
193− H.reflow $
194− "But it needs " <> H.args expected <> ". What is missing? Are some parentheses misplaced?"
194+ D.reflow $
195+ "But it needs " <> D.args expected <> ". What is missing? Are some parentheses misplaced?"
195196 )
196197
197198 else
198199 Report.Report "TOO MANY ARGS" region [] $
199200 Report.toCodeSnippet source region Nothing
200201 (
201− H.reflow $
202+ D.reflow $
202203 "The `" <> N.toString name <> "` " <> thing <> " needs "
203− <> H.args expected <> ", but I see " <> show actual <> " instead:"
204+ <> D.args expected <> ", but I see " <> show actual <> " instead:"
204205 ,
205206 if actual - expected == 1 then
206207 "Which is the extra one? Maybe some parentheses are missing?"
@@ -212,10 +213,10 @@ toReport source err =
212213 Report.Report "INFIX PROBLEM" region [] $
213214 Report.toCodeSnippet source region Nothing
214215 (
215− H.reflow $
216+ D.reflow $
216217 "You cannot mix (" <> N.toString op1 <> ") and (" <> N.toString op2 <> ") without parentheses."
217218 ,
218− H.reflow
219+ D.reflow
219220 "I do not know how to group these expressions. Add parentheses for me!"
220221 )
221222
@@ -269,10 +270,10 @@ toReport source err =
269270 Report.Report "EFFECT PROBLEM" region [] $
270271 Report.toCodeSnippet source region Nothing
271272 (
272− H.reflow $
273+ D.reflow $
273274 "You have declared that `" ++ N.toString name ++ "` is an effect type:"
274275 ,
275− H.reflow $
276+ D.reflow $
276277 "But I cannot find a union type named `" ++ N.toString name ++ "` in this file!"
277278 )
278279
@@ -280,10 +281,10 @@ toReport source err =
280281 Report.Report "EFFECT PROBLEM" region [] $
281282 Report.toCodeSnippet source region Nothing
282283 (
283− H.reflow $
284+ D.reflow $
284285 "This kind of effect module must define a `" ++ N.toString name ++ "` function."
285286 ,
286− H.reflow $
287+ D.reflow $
287288 "But I cannot find `" ++ N.toString name ++ "` in this file!"
288289 )
289290
@@ -296,12 +297,12 @@ toReport source err =
296297 Report.Report "REDUNDANT EXPORT" r2 [] $
297298 Report.toCodePair source r1 r2
298299 (
299− H.reflow messageThatEndsWithPunctuation
300+ D.reflow messageThatEndsWithPunctuation
300301 ,
301302 "Remove one of them and you should be all set!"
302303 )
303304 (
304− H.reflow (messageThatEndsWithPunctuation <> " Once here:")
305+ D.reflow (messageThatEndsWithPunctuation <> " Once here:")
305306 ,
306307 "And again right here:"
307308 ,
@@ -312,27 +313,27 @@ toReport source err =
312313 let
313314 suggestions =
314315 map N.toString $ take 4 $
315− H.nearbyNames N.toString rawName possibleNames
316+ Suggest.nearbyNames N.toString rawName possibleNames
316317 in
317318 Report.Report "UNKNOWN EXPORT" region suggestions $
318319 let (a, thing, name) = toKindInfo kind rawName in
319− H.stack
320− [ H.fillSep
320+ D.stack
321+ [ D.fillSep
321322 ["You","are","trying","to","expose",a,thing,"named"
322323 ,name,"but","I","cannot","find","its","definition."
323324 ]
324− , case map H.text suggestions of
325+ , case map D.fromString suggestions of
325326 [] ->
326− H.reflow $
327+ D.reflow $
327328 "I do not see any super similar names in this file. Is the definition missing?"
328329
329330 [alt] ->
330− H.fillSep ["Maybe","you","want",H.dullyellow alt,"instead?"]
331+ D.fillSep ["Maybe","you","want",D.dullyellow alt,"instead?"]
331332
332333 alts ->
333− H.stack
334+ D.stack
334335 [ "These names seem close though:"
335− , H.indent 4 $ H.vcat $ map H.dullyellow alts
336+ , D.indent 4 $ D.vcat $ map D.dullyellow alts
336337 ]
337338 ]
338339
@@ -340,11 +341,11 @@ toReport source err =
340341 Report.Report "BAD EXPORT" region [] $
341342 Report.toCodeSnippet source region Nothing
342343 (
343− H.reflow $
344+ D.reflow $
344345 "The (..) syntax is for exposing union type constructors. It cannot be used with a type alias like `"
345346 ++ N.toString name ++ "` though."
346347 ,
347− H.reflow $
348+ D.reflow $
348349 "Remove the (..) and you should be fine!"
349350 )
350351
@@ -352,15 +353,15 @@ toReport source err =
352353 Report.Report "BAD IMPORT" region [] $
353354 Report.toCodeSnippet source region Nothing
354355 (
355− H.reflow $
356+ D.reflow $
356357 "You are trying to import the `" <> N.toString ctor
357358 <> "` type constructor by name:"
358359 ,
359− H.fillSep
360− ["Try","importing",H.green (H.nameToDoc tipe <> "(..)"),"instead."
361− ,"The","dots","mean","“expose","the",H.nameToDoc tipe,"type","and"
360+ D.fillSep
361+ ["Try","importing",D.green (D.fromName tipe <> "(..)"),"instead."
362+ ,"The","dots","mean","“expose","the",D.fromName tipe,"type","and"
362363 ,"all","its","constructors”","so","it","gives","you","access","to"
363− , H.nameToDoc ctor <> "."
364+ , D.fromName ctor <> "."
364365 ]
365366 )
366367
@@ -372,7 +373,7 @@ toReport source err =
372373 Report.Report "UNKNOWN IMPORT" region [] $
373374 Report.toCodeSnippet source region Nothing
374375 (
375− H.reflow $
376+ D.reflow $
376377 "I could not find a `" <> N.toString name <> "` module to import!"
377378 ,
378379 mempty
@@ -382,12 +383,12 @@ toReport source err =
382383 Report.Report "BAD IMPORT" region [] $
383384 Report.toCodeSnippet source region Nothing
384385 (
385− H.reflow $
386+ D.reflow $
386387 "The `" <> N.toString name <> "` type alias cannot be followed by (..) like this:"
387388 ,
388− H.stack
389+ D.stack
389390 [ "Remove the (..) and it should work."
390− , H.link "Hint"
391+ , D.link "Hint"
391392 "The distinction between `type` and `type alias` is important here. Read"
392393 "types-vs-type-aliases"
393394 "to learn more."
@@ -398,27 +399,27 @@ toReport source err =
398399 let
399400 suggestions =
400401 map N.toString $ take 4 $
401− H.nearbyNames N.toString home possibleNames
402+ Suggest.nearbyNames N.toString home possibleNames
402403 in
403404 Report.Report "BAD IMPORT" region suggestions $
404405 Report.toCodeSnippet source region Nothing
405406 (
406− H.reflow $
407+ D.reflow $
407408 "The `" <> N.toString home
408409 <> "` module does not expose `"
409410 <> N.toString value <> "`:"
410411 ,
411− case map H.text suggestions of
412+ case map D.fromString suggestions of
412413 [] ->
413414 "I cannot find any super similar exposed names. Maybe it is private?"
414415
415416 [alt] ->
416− H.fillSep ["Maybe","you","want",H.dullyellow alt,"instead?"]
417+ D.fillSep ["Maybe","you","want",D.dullyellow alt,"instead?"]
417418
418419 alts ->
419− H.stack
420+ D.stack
420421 [ "These names seem close though:"
421− , H.indent 4 $ H.vcat $ map H.dullyellow alts
422+ , D.indent 4 $ D.vcat $ map D.dullyellow alts
422423 ]
423424 )
424425
@@ -445,12 +446,12 @@ toReport source err =
445446 Report.Report "UNKNOWN OPERATOR" region ["/="] $
446447 Report.toCodeSnippet source region Nothing
447448 (
448− H.reflow $
449+ D.reflow $
449450 "Elm uses a different name for the “not equal” operator:"
450451 ,
451− H.stack
452− [ H.reflow "Switch to (/=) instead."
453− , H.toSimpleNote $
452+ D.stack
453+ [ D.reflow "Switch to (/=) instead."
454+ , D.toSimpleNote $
454455 "Our (/=) operator is supposed to look like a real “not equal” sign (≠). I hope that history will remember ("
455456 ++ N.toString op ++ ") as a werid and temporary choice."
456457 ]
@@ -460,10 +461,10 @@ toReport source err =
460461 Report.Report "UNKNOWN OPERATOR" region ["^","*"] $
461462 Report.toCodeSnippet source region Nothing
462463 (
463− H.reflow $
464+ D.reflow $
464465 "I do not recognize the (**) operator:"
465466 ,
466− H.reflow $
467+ D.reflow $
467468 "Switch to (^) for exponentiation. Or switch to (*) for multiplication."
468469 )
469470
@@ -471,17 +472,17 @@ toReport source err =
471472 Report.Report "UNKNOWN OPERATOR" region [] $
472473 Report.toCodeSnippet source region Nothing
473474 (
474− H.reflow $
475+ D.reflow $
475476 "Elm does not use (%) as the remainder operator:"
476477 ,
477− H.stack
478− [ H.reflow $
478+ D.stack
479+ [ D.reflow $
479480 "If you want the behavior of (%) like in JavaScript, switch to:\
480481 \ <https://package.elm-lang.org/packages/elm-lang/core/latest/Basics#remainderBy>"
481− , H.reflow $
482+ , D.reflow $
482483 "If you want modular arithmatic like in math, switch to:\
483484 \ <https://package.elm-lang.org/packages/elm-lang/core/latest/Basics#modBy>"
484− , H.reflow $
485+ , D.reflow $
485486 "The difference is how things work when negative numbers are involved."
486487 ]
487488 )
@@ -490,37 +491,37 @@ toReport source err =
490491 let
491492 suggestions =
492493 map N.toString $ take 2 $
493− H.nearbyNames N.toString op (Set.toList locals)
494+ Suggest.nearbyNames N.toString op (Set.toList locals)
494495
495496 format altOp =
496− H.green $ "(" <> altOp <> ")"
497+ D.green $ "(" <> altOp <> ")"
497498 in
498499 Report.Report "UNKNOWN OPERATOR" region suggestions $
499500 Report.toCodeSnippet source region Nothing
500501 (
501− H.reflow $
502+ D.reflow $
502503 "I do not recognize the (" ++ N.toString op ++ ") operator."
503504 ,
504− H.fillSep $
505+ D.fillSep $
505506 ["Is","there","an","`import`","and","`exposing`","entry","for","it?"]
506507 ++
507− case map H.text suggestions of
508+ case map D.fromString suggestions of
508509 [] ->
509510 []
510511
511512 alts ->
512− ["Maybe","you","want"] ++ H.commaSep "or" format alts ++ ["instead?"]
513+ ["Maybe","you","want"] ++ D.commaSep "or" format alts ++ ["instead?"]
513514 )
514515
515516 PatternHasRecordCtor region name ->
516517 Report.Report "BAD PATTERN" region [] $
517518 Report.toCodeSnippet source region Nothing
518519 (
519− H.reflow $
520+ D.reflow $
520521 "You can construct records by using `" <> N.toString name
521522 <> "` as a function, but it is not available in pattern matching like this:"
522523 ,
523− H.reflow $
524+ D.reflow $
524525 "I recommend matching matching the record as a variable and unpacking it later."
525526 )
526527
@@ -530,12 +531,12 @@ toReport source err =
530531 Report.Report "PORT ERROR" region [] $
531532 Report.toCodeSnippet source region Nothing
532533 (
533− H.reflow $
534+ D.reflow $
534535 "The `" <> N.toString portName <> "` port is trying to transmit " <> aBadKindOfThing <> ":"
535536 ,
536− H.stack
537+ D.stack
537538 [ elaboration
538− , H.link "Hint"
539+ , D.link "Hint"
539540 "Ports are not a traditional FFI, so if you have tons of annoying ports, definitely read"
540541 "ports"
541542 "to learn how they are meant to work. They require a different mindset!"
@@ -548,7 +549,7 @@ toReport source err =
548549 (
549550 "an extended record"
550551 ,
551− H.reflow $
552+ D.reflow $
552553 "But the exact shape of the record must be known at compile time. No type variables!"
553554 )
554555
@@ -556,7 +557,7 @@ toReport source err =
556557 (
557558 "a function"
558559 ,
559− H.reflow $
560+ D.reflow $
560561 "But functions cannot be sent in and out ports. If we allowed functions in from JS\
561562 \ they may perform some side-effects. If we let functions out, they could produce\
562563 \ incorrect results because Elm optimizations assume there are no side-effects."
@@ -567,7 +568,7 @@ toReport source err =
567568 (
568569 "an unspecified type"
569570 ,
570− H.reflow $
571+ D.reflow $
571572 "But type variables like `" <> N.toString name <> "` cannot flow through ports.\
572573 \ I need to know exactly what type of data I am getting, so I can guarantee that\
573574 \ unexpected data cannot sneak in and crash the Elm program."
@@ -577,13 +578,13 @@ toReport source err =
577578 (
578579 "a `" <> N.toString name <> "` value"
579580 ,
580− H.stack
581− [ H.reflow $ "I cannot handle that. The types that CAN flow in and out of Elm include:"
582− , H.indent 4 $
583− H.reflow $
581+ D.stack
582+ [ D.reflow $ "I cannot handle that. The types that CAN flow in and out of Elm include:"
583+ , D.indent 4 $
584+ D.reflow $
584585 "Ints, Floats, Bools, Strings, Maybes, Lists, Arrays,\
585586 \ tuples, records, and JSON values."
586− , H.reflow $
587+ , D.reflow $
587588 "Since JSON values can flow through, you can use JSON encoders and decoders\
588589 \ to allow other types through as well. More advanced users often just do\
589590 \ everything with encoders and decoders for more control and better errors."
@@ -596,11 +597,11 @@ toReport source err =
596597 Report.Report "BAD PORT" region [] $
597598 Report.toCodeSnippet source region Nothing $
598599 (
599− H.reflow before
600+ D.reflow before
600601 ,
601− H.stack
602+ D.stack
602603 [ after
603− , H.link "Hint" "Read" "ports"
604+ , D.link "Hint" "Read" "ports"
604605 "for more advice. For example, do not end up with one port per JS function!"
605606 ]
606607 )
@@ -611,7 +612,7 @@ toReport source err =
611612 (
612613 "The `" <> N.toString name <> "` port cannot be just a command."
613614 ,
614− H.reflow $
615+ D.reflow $
615616 "It can be (() -> Cmd msg) if you just need to trigger a JavaScript\
616617 \ function, but there is often a better way to set things up."
617618 )
@@ -626,7 +627,7 @@ toReport source err =
626627 | n == 3 = "these " ++ show n ++ " items into a tuple or record"
627628 | True = "these " ++ show n ++ " items into a record"
628629 in
629− H.reflow $
630+ D.reflow $
630631 "You can put " ++ theseItemsInSomething ++ " to send them out though."
631632 )
632633
@@ -634,7 +635,7 @@ toReport source err =
634635 (
635636 "The `" <> N.toString name <> "` port cannot send any messages to the `update` function."
636637 ,
637− H.reflow $
638+ D.reflow $
638639 "It must produce a (Cmd msg) type. Notice the lower case `msg` type\
639640 \ variable. The command will trigger some JS code, but it will not send\
640641 \ anything particular back to Elm."
@@ -643,12 +644,12 @@ toReport source err =
643644 SubBad ->
644645 ( "There is something off about this `" <> N.toString name <> "` port declaration."
645646 ,
646− H.stack
647− [ H.reflow $
647+ D.stack
648+ [ D.reflow $
648649 "To receive messages from JavaScript, you need to define a port like this:"
649− , H.indent 4 $ H.dullyellow $ H.text $
650+ , D.indent 4 $ D.dullyellow $ D.fromString $
650651 "port " <> N.toString name <> " : (Int -> msg) -> Sub msg"
651− , H.reflow $
652+ , D.reflow $
652653 "Now every time JS sends an `Int` to this port, it is converted to a `msg`.\
653654 \ And if you subscribe, those `msg` values will be piped into your `update`\
654655 \ function. The only thing you can customize here is the `Int` type."
@@ -659,7 +660,7 @@ toReport source err =
659660 (
660661 "I am confused about the `" <> N.toString name <> "` port declaration."
661662 ,
662− H.reflow $
663+ D.reflow $
663664 "Ports need to produce a command (Cmd) or a subscription (Sub) but\
664665 \ this is neither. I do not know how to handle this."
665666 )
@@ -675,7 +676,7 @@ toReport source err =
675676 Can.TypedDef name _ _ _ _ -> name
676677
677678 makeTheory question details =
678− H.fillSep $ map (H.dullyellow . H.text) (words question) ++ map H.text (words details)
679+ D.fillSep $ map (D.dullyellow . D.fromString) (words question) ++ map D.fromString (words details)
679680 in
680681 case map toName cyclicValueDefs of
681682 [] ->
@@ -690,10 +691,10 @@ toReport source err =
690691 case map A.toValue otherNames of
691692 [] ->
692693 (
693− H.reflow $
694+ D.reflow $
694695 "The `" <> N.toString name <> "` value is defined directly in terms of itself, causing an infinite loop."
695696 ,
696− H.stack
697+ D.stack
697698 [ makeTheory "Are you are trying to mutate a variable?" $
698699 "Elm does not have mutation, so when I see " ++ N.toString name
699700 ++ " defined in terms of " ++ N.toString name
@@ -702,7 +703,7 @@ toReport source err =
702703 "To define " ++ N.toString name ++ " we need to know what " ++ N.toString name
703704 ++ " is, so let’s expand it. Wait, but now we need to know what " ++ N.toString name
704705 ++ " is, so let’s expand it... This will keep going infinitely!"
705− , H.link "Hint"
706+ , D.link "Hint"
706707 "The root problem is often a typo in some variable name, but I recommend reading"
707708 "bad-recursion"
708709 "for more detailed advice, especially if you actually do need a recursive value."
@@ -711,15 +712,15 @@ toReport source err =
711712
712713 names ->
713714 (
714− H.reflow $
715+ D.reflow $
715716 "The `" <> N.toString name <> "` definition is causing a very tricky infinite loop."
716717 ,
717− H.stack
718− [ H.reflow $
718+ D.stack
719+ [ D.reflow $
719720 "The `" <> N.toString name
720721 <> "` value depends on itself through the following chain of definitions:"
721− , H.indent 4 $ H.drawCycle (name:names)
722− , H.link "Hint"
722+ , D.cycle 4 (name:names)
723+ , D.link "Hint"
723724 "The root problem is often a typo in some variable name, but I recommend reading"
724725 "bad-recursion"
725726 "for more detailed advice, especially if you actually do want mutually recursive values."
@@ -733,13 +734,13 @@ toReport source err =
733734 [] ->
734735 let
735736 makeTheory question details =
736− H.fillSep $ map (H.dullyellow . H.text) (words question) ++ map H.text (words details)
737+ D.fillSep $ map (D.dullyellow . D.fromString) (words question) ++ map D.fromString (words details)
737738 in
738739 (
739− H.reflow $
740+ D.reflow $
740741 "The `" <> N.toString name <> "` value is defined directly in terms of itself, causing an infinite loop."
741742 ,
742− H.stack
743+ D.stack
743744 [ makeTheory "Are you are trying to mutate a variable?" $
744745 "Elm does not have mutation, so when I see " ++ N.toString name
745746 ++ " defined in terms of " ++ N.toString name
@@ -748,7 +749,7 @@ toReport source err =
748749 "To define " ++ N.toString name ++ " we need to know what " ++ N.toString name
749750 ++ " is, so let’s expand it. Wait, but now we need to know what " ++ N.toString name
750751 ++ " is, so let’s expand it... This will keep going infinitely!"
751− , H.link "Hint"
752+ , D.link "Hint"
752753 "The root problem is often a typo in some variable name, but I recommend reading"
753754 "bad-recursion"
754755 "for more detailed advice, especially if you actually do need a recursive value."
@@ -757,15 +758,15 @@ toReport source err =
757758
758759 _ ->
759760 (
760− H.reflow $
761+ D.reflow $
761762 "I do not allow cyclic values in `let` expressions."
762763 ,
763− H.stack
764− [ H.reflow $
764+ D.stack
765+ [ D.reflow $
765766 "The `" <> N.toString name
766767 <> "` value depends on itself through the following chain of definitions:"
767− , H.indent 4 $ H.drawCycle (name:names)
768− , H.link "Hint"
768+ , D.cycle 4 (name:names)
769+ , D.link "Hint"
769770 "The root problem is often a typo in some variable name, but I recommend reading"
770771 "bad-recursion"
771772 "for more detailed advice, especially if you actually do want mutually recursive values."
@@ -778,16 +779,16 @@ toReport source err =
778779 ( "These variables cannot have the same name:"
779780 , advice
780781 )
781− ( H.reflow $ "The name `" <> N.toString name <> "` is first defined here:"
782+ ( D.reflow $ "The name `" <> N.toString name <> "` is first defined here:"
782783 , "But then it is defined AGAIN over here:"
783784 , advice
784785 )
785786 where
786787 advice =
787− H.stack
788− [ H.reflow $
788+ D.stack
789+ [ D.reflow $
789790 "Think of a more helpful name for one of them and you should be all set!"
790− , H.link "Note"
791+ , D.link "Note"
791792 "Linters advise against shadowing, so Elm makes “best practices” the default. Read"
792793 "shadowing"
793794 "for more details on this choice."
@@ -799,12 +800,12 @@ toReport source err =
799800 (
800801 "I only accept tuples with two or three items. This has too many:"
801802 ,
802− H.stack
803− [ H.reflow $
803+ D.stack
804+ [ D.reflow $
804805 "I recommend switching to records. Each item will be named, and you can use\
805806 \ the `point.x` syntax to access them."
806807
807− , H.link "Note" "Read" "tuples"
808+ , D.link "Note" "Read" "tuples"
808809
809810 "for more comprehensive advice on working with large chunks of data in Elm."
810811 ]
@@ -818,7 +819,7 @@ toReport source err =
818819 (unused:unuseds, []) ->
819820 let
820821 backQuote name =
821− "`" <> H.nameToDoc name <> "`"
822+ "`" <> D.fromName name <> "`"
822823
823824 allUnusedNames =
824825 map fst unusedVars
@@ -831,31 +832,31 @@ toReport source err =
831832 , ["Type","alias",backQuote typeName,"does","not","use","the"
832833 ,backQuote (fst unused),"type","variable."
833834 ]
834− , [H.dullyellow (backQuote (fst unused))]
835+ , [D.dullyellow (backQuote (fst unused))]
835836 )
836837
837838 _:_ ->
838839 ( "UNUSED TYPE VARIABLES"
839840 , Nothing
840841 , ["Type","variables"]
841− ++ H.commaSep "and" id (map H.nameToDoc allUnusedNames)
842+ ++ D.commaSep "and" id (map D.fromName allUnusedNames)
842843 ++ ["are","unused","in","the",backQuote typeName,"definition."]
843− , H.commaSep "and" H.dullyellow (map H.nameToDoc allUnusedNames)
844+ , D.commaSep "and" D.dullyellow (map D.fromName allUnusedNames)
844845 )
845846 in
846847 Report.Report title aliasRegion [] $
847848 Report.toCodeSnippet source aliasRegion subRegion
848849 (
849− H.fillSep overview
850+ D.fillSep overview
850851 ,
851− H.stack
852− [ H.fillSep $
852+ D.stack
853+ [ D.fillSep $
853854 ["I","recommend","removing"] ++ stuff ++ ["from","the","declaration,","like","this:"]
854− , H.indent 4 $ H.hsep $
855− ["type","alias",H.green (H.nameToDoc typeName)]
856− ++ map H.nameToDoc (filter (`notElem` allUnusedNames) allVars)
855+ , D.indent 4 $ D.hsep $
856+ ["type","alias",D.green (D.fromName typeName)]
857+ ++ map D.fromName (filter (`notElem` allUnusedNames) allVars)
857858 ++ ["=", "..."]
858− , H.reflow $
859+ , D.reflow $
859860 "Why? Well, if I allowed `type alias Height a = Float` I would need to answer\
860861 \ some weird questions. Is `Height Bool` the same as `Float`? Is `Height Bool`\
861862 \ the same as `Height Int`? My solution is to not need to ask them!"
@@ -873,43 +874,43 @@ toReport source err =
873874 theseAreUsed =
874875 case unbound of
875876 [x] ->
876− ["Type","variable",H.dullyellow ("`" <> H.nameToDoc x <> "`"),"appears"
877+ ["Type","variable",D.dullyellow ("`" <> D.fromName x <> "`"),"appears"
877878 ,"in","the","definition,","but","I","do","not","see","it","declared."
878879 ]
879880
880881 _ ->
881882 ["Type","variables"]
882− ++ H.commaSep "and" H.dullyellow (map H.nameToDoc unbound)
883+ ++ D.commaSep "and" D.dullyellow (map D.fromName unbound)
883884 ++ ["are","used","in","the","definition,","but","I","do","not","see","them","declared."]
884885
885886 butTheseAreUnused =
886887 case unused of
887888 [x] ->
888889 ["Likewise,","type","variable"
889− ,H.dullyellow ("`" <> H.nameToDoc x <> "`")
890+ ,D.dullyellow ("`" <> D.fromName x <> "`")
890891 ,"is","delared,","but","not","used."
891892 ]
892893
893894 _ ->
894895 ["Likewise,","type","variables"]
895− ++ H.commaSep "and" H.dullyellow (map H.nameToDoc unused)
896+ ++ D.commaSep "and" D.dullyellow (map D.fromName unused)
896897 ++ ["are","delared,","but","not","used."]
897898
898899 in
899900 Report.Report "TYPE VARIABLE PROBLEMS" aliasRegion [] $
900901 Report.toCodeSnippet source aliasRegion Nothing
901902 (
902− H.reflow $
903+ D.reflow $
903904 "Type alias `" <> N.toString typeName <> "` has some type variable problems."
904905 ,
905− H.stack
906− [ H.fillSep $ theseAreUsed ++ butTheseAreUnused
907− , H.reflow $
906+ D.stack
907+ [ D.fillSep $ theseAreUsed ++ butTheseAreUnused
908+ , D.reflow $
908909 "My guess is that a definition like this will work better:"
909− , H.indent 4 $ H.hsep $
910− ["type", "alias", H.nameToDoc typeName]
911− ++ map H.nameToDoc (filter (`notElem` unused) allVars)
912− ++ map (H.green . H.nameToDoc) unbound
910+ , D.indent 4 $ D.hsep $
911+ ["type", "alias", D.fromName typeName]
912+ ++ map D.fromName (filter (`notElem` unused) allVars)
913+ ++ map (D.green . D.fromName) unbound
913914 ++ ["=", "..."]
914915 ]
915916 )
@@ -919,11 +920,11 @@ toReport source err =
919920-- BAD TYPE VARIABLES
920921
921922
922−unboundTypeVars :: Code.Source -> R.Region -> [H.Doc] -> N.Name -> [N.Name] -> (N.Name, R.Region) -> [(N.Name, R.Region)] -> Report.Report
923+unboundTypeVars :: Code.Source -> R.Region -> [D.Doc] -> N.Name -> [N.Name] -> (N.Name, R.Region) -> [(N.Name, R.Region)] -> Report.Report
923924unboundTypeVars source declRegion tipe typeName allVars (unboundVar, varRegion) unboundVars =
924925 let
925926 backQuote name =
926− "`" <> H.nameToDoc name <> "`"
927+ "`" <> D.fromName name <> "`"
927928
928929 (title, subRegion, overview) =
929930 case map fst unboundVars of
@@ -932,32 +933,32 @@ unboundTypeVars source declRegion tipe typeName allVars (unboundVar, varRegion)
932933 , Just varRegion
933934 , ["The",backQuote typeName]
934935 ++ tipe
935− ++ ["uses","an","unbound","type","variable",H.dullyellow (backQuote unboundVar),"in","its","definition:"]
936+ ++ ["uses","an","unbound","type","variable",D.dullyellow (backQuote unboundVar),"in","its","definition:"]
936937 )
937938
938939 vars ->
939940 ( "UNBOUND TYPE VARIABLES"
940941 , Nothing
941942 , ["Type","variables"]
942− ++ H.commaSep "and" H.dullyellow (H.nameToDoc unboundVar : map H.nameToDoc vars)
943+ ++ D.commaSep "and" D.dullyellow (D.fromName unboundVar : map D.fromName vars)
943944 ++ ["are","unbound","in","the",backQuote typeName] ++ tipe ++ ["definition:"]
944945 )
945946 in
946947 Report.Report title declRegion [] $
947948 Report.toCodeSnippet source declRegion subRegion
948949 (
949− H.fillSep overview
950+ D.fillSep overview
950951 ,
951− H.stack
952− [ H.reflow $
952+ D.stack
953+ [ D.reflow $
953954 "You probably need to change the declaration to something like this:"
954− , H.indent 4 $ H.hsep $
955+ , D.indent 4 $ D.hsep $
955956 tipe
956− ++ [H.nameToDoc typeName]
957− ++ map H.nameToDoc allVars
958− ++ map (H.green . H.nameToDoc) (unboundVar : map fst unboundVars)
957+ ++ [D.fromName typeName]
958+ ++ map D.fromName allVars
959+ ++ map (D.green . D.fromName) (unboundVar : map fst unboundVars)
959960 ++ ["=", "..."]
960− , H.reflow $
961+ , D.reflow $
961962 "Why? Well, imagine one `" ++ N.toString typeName ++ "` where `" ++ N.toString unboundVar ++
962963 "` is an Int and another where it is a Bool. When we explicitly list the type\
963964 \ variables, the type checker can see that they are actually different types."
@@ -974,12 +975,12 @@ nameClash source r1 r2 messageThatEndsWithPunctuation =
974975 Report.Report "NAME CLASH" r2 [] $
975976 Report.toCodePair source r1 r2
976977 (
977− H.reflow messageThatEndsWithPunctuation
978+ D.reflow messageThatEndsWithPunctuation
978979 ,
979980 "How can I know which one you want? Rename one of them!"
980981 )
981982 (
982− H.reflow (messageThatEndsWithPunctuation <> " One here:")
983+ D.reflow (messageThatEndsWithPunctuation <> " One here:")
983984 ,
984985 "And another one here:"
985986 ,
@@ -999,20 +1000,20 @@ ambiguousName source region maybePrefix name possibleHomes thing =
9991000 Nothing ->
10001001 let
10011002 homeToYellowDoc (ModuleName.Canonical _ home) =
1002− H.dullyellow (H.nameToDoc home)
1003+ D.dullyellow (D.fromName home)
10031004
10041005 bothOrAll =
10051006 if length possibleHomes == 2 then "both" else "all"
10061007 in
10071008 (
1008− H.reflow $ "This usage of `" ++ N.toString name ++ "` is ambiguous."
1009+ D.reflow $ "This usage of `" ++ N.toString name ++ "` is ambiguous."
10091010 ,
1010− H.stack
1011− [ H.reflow $
1011+ D.stack
1012+ [ D.reflow $
10121013 "Check your imports. The following modules " ++ bothOrAll
10131014 ++ " expose a `" ++ N.toString name ++ "` " ++ thing ++ ":"
1014− , H.indent 4 $ H.vcat $ map homeToYellowDoc possibleHomes
1015− , H.reflowLink "Read" "imports" "to learn how to clarify which one you want."
1015+ , D.indent 4 $ D.vcat $ map homeToYellowDoc possibleHomes
1016+ , D.reflowLink "Read" "imports" "to learn how to clarify which one you want."
10161017 ]
10171018 )
10181019
@@ -1020,22 +1021,22 @@ ambiguousName source region maybePrefix name possibleHomes thing =
10201021 let
10211022 homeToYellowDoc (ModuleName.Canonical _ home) =
10221023 if prefix == home then
1023− H.blue "import" <+> H.dullyellow (H.nameToDoc home)
1024+ D.blue "import" <+> D.dullyellow (D.fromName home)
10241025 else
1025− H.blue "import" <+> H.dullyellow (H.nameToDoc home) <+> H.blue "as" <+> H.dullyellow (H.nameToDoc prefix)
1026+ D.blue "import" <+> D.dullyellow (D.fromName home) <+> D.blue "as" <+> D.dullyellow (D.fromName prefix)
10261027
10271028 eitherOrAny =
10281029 if length possibleHomes == 2 then "either" else "any"
10291030 in
10301031 (
1031− H.reflow $ "This usage of `" ++ toQualString prefix name ++ "` is ambiguous."
1032+ D.reflow $ "This usage of `" ++ toQualString prefix name ++ "` is ambiguous."
10321033 ,
1033− H.stack
1034− [ H.reflow $
1034+ D.stack
1035+ [ D.reflow $
10351036 "It could refer to a " ++ thing ++ " from "
10361037 ++ eitherOrAny ++ " of these imports:"
1037− , H.indent 4 $ H.vcat $ map homeToYellowDoc possibleHomes
1038− , H.reflowLink "Read" "imports" "to learn how to clarify which one you want."
1038+ , D.indent 4 $ D.vcat $ map homeToYellowDoc possibleHomes
1039+ , D.reflowLink "Read" "imports" "to learn how to clarify which one you want."
10391040 ]
10401041 )
10411042
@@ -1058,28 +1059,28 @@ notFound source region maybePrefix name thing (PossibleNames locals quals) =
10581059 Map.foldrWithKey addQuals (map N.toString (Set.toList locals)) quals
10591060
10601061 nearbyNames =
1061− take 4 (H.nearbyNames id givenName possibleNames)
1062+ take 4 (Suggest.nearbyNames id givenName possibleNames)
10621063
10631064 toDetails noSuggestionDetails yesSuggestionDetails =
10641065 case nearbyNames of
10651066 [] ->
1066− H.stack
1067− [ H.reflow noSuggestionDetails
1068− , H.link "Hint" "Read" "imports" "to see how `import` declarations work in Elm."
1067+ D.stack
1068+ [ D.reflow noSuggestionDetails
1069+ , D.link "Hint" "Read" "imports" "to see how `import` declarations work in Elm."
10691070 ]
10701071
10711072 suggestions ->
1072− H.stack
1073− [ H.reflow yesSuggestionDetails
1074− , H.indent 4 $ H.vcat $ map H.dullyellow $ map H.text suggestions
1075− , H.link "Hint" "Read" "imports" "to see how `import` declarations work in Elm."
1073+ D.stack
1074+ [ D.reflow yesSuggestionDetails
1075+ , D.indent 4 $ D.vcat $ map D.dullyellow $ map D.fromString suggestions
1076+ , D.link "Hint" "Read" "imports" "to see how `import` declarations work in Elm."
10761077 ]
10771078
10781079 in
10791080 Report.Report "NAMING ERROR" region nearbyNames $
10801081 Report.toCodeSnippet source region Nothing
10811082 (
1082− H.reflow $
1083+ D.reflow $
10831084 "I cannot find a `" ++ givenName ++ "` " ++ thing ++ ":"
10841085 ,
10851086 case maybePrefix of
@@ -1115,20 +1116,20 @@ varErrorToReport :: VarError -> Report.Report
11151116varErrorToReport (VarError kind name problem suggestions) =
11161117 let
11171118 learnMore orMaybe =
1118− H.reflow $
1119+ D.reflow $
11191120 orMaybe <> " `import` works different than you expect? Learn all about it here: "
1120− <> H.hintLink "imports"
1121+ <> D.hintLink "imports"
11211122
11221123 namingError overview maybeStarter specializedSuggestions =
11231124 Report.reportDoc "NAMING ERROR" Nothing overview $
1124− case H.maybeYouWant' maybeStarter specializedSuggestions of
1125+ case D.maybeYouWant' maybeStarter specializedSuggestions of
11251126 Nothing ->
11261127 learnMore "Maybe"
11271128 Just doc ->
1128− H.stack [ doc, learnMore "Or maybe" ]
1129+ D.stack [ doc, learnMore "Or maybe" ]
11291130
11301131 specialNamingError specialHint =
1131− Report.reportDoc "NAMING ERROR" Nothing (cannotFind kind name) (H.hsep specialHint)
1132+ Report.reportDoc "NAMING ERROR" Nothing (cannotFind kind name) (D.hsep specialHint)
11321133 in
11331134 case problem of
11341135 Ambiguous ->
@@ -1158,35 +1159,35 @@ varErrorToReport (VarError kind name problem suggestions) =
11581159cannotFind :: VarKind -> Text -> [Doc]
11591160cannotFind kind rawName =
11601161 let ( a, thing, name ) = toKindInfo kind rawName in
1161− [ "Cannot", "find", a, thing, "named", H.dullyellow name <> ":" ]
1162+ [ "Cannot", "find", a, thing, "named", D.dullyellow name <> ":" ]
11621163
11631164
11641165ambiguous :: VarKind -> Text -> [Doc]
11651166ambiguous kind rawName =
11661167 let ( _a, thing, name ) = toKindInfo kind rawName in
1167− [ "This", "usage", "of", "the", H.dullyellow name, thing, "is", "ambiguous." ]
1168+ [ "This", "usage", "of", "the", D.dullyellow name, thing, "is", "ambiguous." ]
11681169
11691170
11701171notEqualsHint :: Text -> [Doc]
11711172notEqualsHint op =
11721173 [ "Looking", "for", "the", "“not", "equal”", "operator?", "The", "traditional"
1173− , H.dullyellow $ text $ "(" <> op <> ")"
1174− , "is", "replaced", "by", H.green "(/=)", "in", "Elm.", "It", "is", "meant"
1174+ , D.dullyellow $ text $ "(" <> op <> ")"
1175+ , "is", "replaced", "by", D.green "(/=)", "in", "Elm.", "It", "is", "meant"
11751176 , "to", "look", "like", "the", "“not", "equal”", "sign", "from", "math!", "(≠)"
11761177 ]
11771178
11781179
11791180equalsHint :: [Doc]
11801181equalsHint =
1181− [ "A", "special", H.dullyellow "(===)", "operator", "is", "not", "needed"
1182− , "in", "Elm.", "We", "use", H.green "(==)", "for", "everything!"
1182+ [ "A", "special", D.dullyellow "(===)", "operator", "is", "not", "needed"
1183+ , "in", "Elm.", "We", "use", D.green "(==)", "for", "everything!"
11831184 ]
11841185
11851186
11861187modHint :: [Doc]
11871188modHint =
1188− [ "Rather", "than", "a", H.dullyellow "(%)", "operator,"
1189− , "Elm", "has", "a", H.green "modBy", "function."
1189+ [ "Rather", "than", "a", D.dullyellow "(%)", "operator,"
1190+ , "Elm", "has", "a", D.green "modBy", "function."
11901191 , "Learn", "more", "here:"
11911192 , "<https://package.elm-lang.org/packages/elm-lang/core/latest/Basics#modBy>"
11921193 ]
@@ -1209,10 +1210,10 @@ _argMismatchReport source region kind name expected actual =
12091210 Report.Report (map Char.toUpper numArgs) region [] $
12101211 Report.toCodeSnippet source region Nothing
12111212 (
1212− H.reflow $
1213+ D.reflow $
12131214 kind <> " " <> N.toString name <> " has " <> numArgs <> "."
12141215 ,
1215− H.reflow $
1216+ D.reflow $
12161217 "Expecting " <> show expected <> ", but got " <> show actual <> "."
12171218 )
12181219
@@ -1230,13 +1231,13 @@ aliasRecursionReport source region name args tipe others =
12301231 (
12311232 "This type alias is recursive, forming an infinite type!"
12321233 ,
1233− H.stack
1234− [ H.reflow $
1234+ D.stack
1235+ [ D.reflow $
12351236 "When I expand a recursive type alias, it just keeps getting bigger and bigger.\
12361237 \ So dealiasing results in an infinitely large type! Try this instead:"
1237− , H.indent 4 $
1238+ , D.indent 4 $
12381239 aliasToUnionDoc name args tipe
1239− , H.link "Hint"
1240+ , D.link "Hint"
12401241 "This is kind of a subtle distinction. I suggested the naive fix, but I recommend reading"
12411242 "recursive-alias"
12421243 "for ideas on how to do better."
@@ -1249,12 +1250,12 @@ aliasRecursionReport source region name args tipe others =
12491250 (
12501251 "This type alias is part of a mutually recursive set of type aliases."
12511252 ,
1252− H.stack
1253+ D.stack
12531254 [ "It is part of this cycle of type aliases:"
1254− , H.indent 4 (H.drawCycle (name:others))
1255− , H.reflow $
1255+ , D.cycle 4 (name:others)
1256+ , D.reflow $
12561257 "You need to convert at least one of these type aliases into a `type`."
1257− , H.link "Note" "Read" "recursive-alias"
1258+ , D.link "Note" "Read" "recursive-alias"
12581259 "to learn why this `type` vs `type alias` distinction matters. It is subtle but important!"
12591260 ]
12601261 )
@@ -1262,11 +1263,11 @@ aliasRecursionReport source region name args tipe others =
12621263
12631264aliasToUnionDoc :: N.Name -> [N.Name] -> Src.Type -> Doc
12641265aliasToUnionDoc name args tipe =
1265− H.vcat
1266− [ H.dullyellow $
1267− "type" <+> H.nameToDoc name <+> (foldr (<+>) "=" (map H.nameToDoc args))
1268− , H.green $
1269− H.indent 4 (H.nameToDoc name)
1270− , H.dullyellow $
1271− H.indent 8 (RT.srcToDoc RT.App tipe)
1266+ D.vcat
1267+ [ D.dullyellow $
1268+ "type" <+> D.fromName name <+> (foldr (<+>) "=" (map D.fromName args))
1269+ , D.green $
1270+ D.indent 4 (D.fromName name)
1271+ , D.dullyellow $
1272+ D.indent 8 (RT.srcToDoc RT.App tipe)
12721273 ]
compiler/src/Reporting/Error/Docs.hs+24−24
@@ -8,8 +8,8 @@ module Reporting.Error.Docs
88
99
1010import qualified Elm.Name as N
11−import Reporting.Helpers ((<>))
12−import qualified Reporting.Helpers as H
11+import Reporting.Doc ((<>))
12+import qualified Reporting.Doc as D
1313import qualified Reporting.Region as R
1414import qualified Reporting.Render.Code as Code
1515import qualified Reporting.Report as Report
@@ -35,24 +35,24 @@ toReport source err =
3535 case err of
3636 NoDocs region ->
3737 Report.Report "NO DOCS" region [] $
38− H.stack
38+ D.stack
3939 [
40− H.reflow $
40+ D.reflow $
4141 "You must have a documentation comment between the module\
4242 \ declaration and the imports."
4343 ,
44− H.reflow
44+ D.reflow
4545 "Learn more at <http://package.elm-lang.org/help/documentation-format>"
4646 ]
4747
4848 ImplicitExposing region ->
4949 Report.Report "IMPLICIT EXPOSING" region [] $
50− H.stack
50+ D.stack
5151 [
52− H.reflow $
52+ D.reflow $
5353 "I need you to be explicit about what this module exposes:"
5454 ,
55− H.reflow $
55+ D.reflow $
5656 "A great API usually hides some implementation details, so it is rare that\
5757 \ everything in the file should be exposed. And requiring package authors\
5858 \ to be explicit about this is a way of adding another quality check before\
@@ -64,14 +64,14 @@ toReport source err =
6464 Report.Report "DUPLICATE DOCS" r2 [] $
6565 Report.toCodePair source r1 r2
6666 (
67− H.reflow $
67+ D.reflow $
6868 "There can only be one `" <> N.toString name
6969 <> "` in your module documentation, but it is listed twice:"
7070 ,
7171 "Remove one of them!"
7272 )
7373 (
74− H.reflow $
74+ D.reflow $
7575 "There can only be one `" <> N.toString name
7676 <> "` in your module documentation, but I see two. One here:"
7777 ,
@@ -84,11 +84,11 @@ toReport source err =
8484 Report.Report "DOCS MISTAKE" region [] $
8585 Report.toCodeSnippet source region Nothing
8686 (
87− H.reflow $
87+ D.reflow $
8888 "I do not see `" <> N.toString name
8989 <> "` in the `exposing` list, but it is in your module documentation:"
9090 ,
91− H.reflow $
91+ D.reflow $
9292 "Does it need to be added to the `exposing` list as well? Or maybe you removed `"
9393 <> N.toString name <> "` and forgot to delete it here?"
9494 )
@@ -97,15 +97,15 @@ toReport source err =
9797 Report.Report "DOCS MISTAKE" region [] $
9898 Report.toCodeSnippet source region Nothing
9999 (
100− H.reflow $
100+ D.reflow $
101101 "I do not see `" <> N.toString name
102102 <> "` in your module documentation, but it is in your `exposing` list:"
103103 ,
104− H.stack
105− [ H.reflow $
104+ D.stack
105+ [ D.reflow $
106106 "Add a line like `@docs " <> N.toString name
107107 <> "` to your module documentation!"
108− , H.link "Note" "See" "docs" "for more guidance on writing high quality docs."
108+ , D.link "Note" "See" "docs" "for more guidance on writing high quality docs."
109109 ]
110110 )
111111
@@ -113,13 +113,13 @@ toReport source err =
113113 Report.Report "NO DOCS" region [] $
114114 Report.toCodeSnippet source region Nothing
115115 (
116− H.reflow $
116+ D.reflow $
117117 "The `" <> N.toString name <> "` definition does not have a documentation comment."
118118 ,
119− H.stack
120− [ H.reflow $
119+ D.stack
120+ [ D.reflow $
121121 "Add documentation with nice examples of how to use it!"
122− , H.link "Note" "Read" "docs" "for more advice on writing great docs. There are a couple important tricks!"
122+ , D.link "Note" "Read" "docs" "for more advice on writing great docs. There are a couple important tricks!"
123123 ]
124124 )
125125
@@ -127,14 +127,14 @@ toReport source err =
127127 Report.Report "NO TYPE ANNOTATION" region [] $
128128 Report.toCodeSnippet source region Nothing
129129 (
130− H.reflow $
130+ D.reflow $
131131 "The `" <> N.toString name <> "` definition does not have a type annotation."
132132 ,
133− H.stack
134− [ H.reflow $
133+ D.stack
134+ [ D.reflow $
135135 "I use the type variable names from your annotations when generating docs. So if\
136136 \ you say `Html msg` in your type annotation, I can use `msg` in the docs and make\
137137 \ them a bit clearer. So add an annotation and try to use nice type variables!"
138− , H.link "Note" "Read" "docs" "for more advice on writing great docs. There are a couple important tricks!"
138+ , D.link "Note" "Read" "docs" "for more advice on writing great docs. There are a couple important tricks!"
139139 ]
140140 )
compiler/src/Reporting/Error/Main.hs+16−16
@@ -9,8 +9,8 @@ module Reporting.Error.Main
99
1010import qualified AST.Canonical as Can
1111import qualified Elm.Name as N
12+import qualified Reporting.Doc as D
1213import qualified Reporting.Error.Canonicalize as E
13−import qualified Reporting.Helpers as H
1414import qualified Reporting.Region as R
1515import qualified Reporting.Render.Code as Code
1616import qualified Reporting.Render.Type as RT
@@ -40,10 +40,10 @@ toReport source err =
4040 (
4141 "I cannot handle this type of `main` value:"
4242 ,
43− H.stack
43+ D.stack
4444 [ "The type of `main` value I am seeing is:"
45− , H.indent 4 $ H.dullyellow $ RT.canToDoc RT.None tipe
46− , H.reflow $
45+ , D.indent 4 $ D.dullyellow $ RT.canToDoc RT.None tipe
46+ , D.reflow $
4747 "I only know how to handle Html, Svg, and Programs\
4848 \ though. Modify `main` to be one of those types of values!"
4949 ]
@@ -55,11 +55,11 @@ toReport source err =
5555 (
5656 "A `main` definition cannot be defined in terms of itself."
5757 ,
58− H.stack
59− [ H.reflow $
58+ D.stack
59+ [ D.reflow $
6060 "It should be a boring value with no recursion. But\
6161 \ instead it is involved in this cycle of definitions:"
62− , H.indent 4 (H.drawCycle cycleNames)
62+ , D.cycle 4 cycleNames
6363 ]
6464 )
6565
@@ -69,7 +69,7 @@ toReport source err =
6969 Report.Report "BAD FLAGS" region [] $
7070 Report.toCodeSnippet source region Nothing
7171 (
72− H.reflow $
72+ D.reflow $
7373 "Your `main` program wants " ++ aBadKindOfThing ++ " from JavaScript."
7474 ,
7575 butThatIsNoGood
@@ -81,7 +81,7 @@ toReport source err =
8181 (
8282 "an extended record"
8383 ,
84− H.reflow $
84+ D.reflow $
8585 "But the exact shape of the record must be known at compile time. No type variables!"
8686 )
8787
@@ -89,7 +89,7 @@ toReport source err =
8989 (
9090 "a function"
9191 ,
92− H.reflow $
92+ D.reflow $
9393 "But if I allowed functions from JS, it would be possible to sneak\
9494 \ side-effects and runtime exceptions into Elm!"
9595 )
@@ -98,7 +98,7 @@ toReport source err =
9898 (
9999 "an unspecified type"
100100 ,
101− H.reflow $
101+ D.reflow $
102102 "But type variables like `" ++ N.toString name ++ "` cannot be given as flags.\
103103 \ I need to know exactly what type of data I am getting, so I can guarantee that\
104104 \ unexpected data cannot sneak in and crash the Elm program."
@@ -108,13 +108,13 @@ toReport source err =
108108 (
109109 "a `" ++ N.toString name ++ "` value"
110110 ,
111− H.stack
112− [ H.reflow $ "I cannot handle that. The types that CAN be in flags include:"
113− , H.indent 4 $
114− H.reflow $
111+ D.stack
112+ [ D.reflow $ "I cannot handle that. The types that CAN be in flags include:"
113+ , D.indent 4 $
114+ D.reflow $
115115 "Ints, Floats, Bools, Strings, Maybes, Lists, Arrays,\
116116 \ tuples, records, and JSON values."
117− , H.reflow $
117+ , D.reflow $
118118 "Since JSON values can flow through, you can use JSON encoders and decoders\
119119 \ to allow other types through as well. More advanced users often just do\
120120 \ everything with encoders and decoders for more control and better errors."
compiler/src/Reporting/Error/Pattern.hs+21−21
@@ -9,10 +9,10 @@ module Reporting.Error.Pattern
99import qualified Data.List as List
1010
1111import qualified Nitpick.PatternMatches as P
12+import Reporting.Doc ((<>))
13+import qualified Reporting.Doc as D
1214import qualified Reporting.Report as Report
1315import qualified Reporting.Render.Code as Code
14−import qualified Reporting.Helpers as H
15−import Reporting.Helpers ((<>))
1616
1717
1818
@@ -26,10 +26,10 @@ toReport source err =
2626 Report.Report "REDUNDANT PATTERN" patternRegion [] $
2727 Report.toCodeSnippet source caseRegion (Just patternRegion)
2828 (
29− H.reflow $
30− "The " <> H.ordinalize index <> " pattern is redundant:"
29+ D.reflow $
30+ "The " <> D.ordinalize index <> " pattern is redundant:"
3131 ,
32− H.reflow $
32+ D.reflow $
3333 "Any value with this shape will be handled by a previous\
3434 \ pattern, so it should be removed."
3535 )
@@ -42,10 +42,10 @@ toReport source err =
4242 (
4343 "This pattern does not cover all possiblities:"
4444 ,
45− H.stack
45+ D.stack
4646 [ "Other possibilities include:"
4747 , unhandledPatternsToDocBlock unhandled
48− , H.reflow $
48+ , D.reflow $
4949 "I would have to crash if I saw one of those! So rather than\
5050 \ pattern matching in function arguments, put a `case` in\
5151 \ the function body to account for all possibilities."
@@ -58,14 +58,14 @@ toReport source err =
5858 (
5959 "This pattern does not cover all possible values:"
6060 ,
61− H.stack
61+ D.stack
6262 [ "Other possibilities include:"
6363 , unhandledPatternsToDocBlock unhandled
64− , H.reflow $
64+ , D.reflow $
6565 "I would have to crash if I saw one of those! You can use\
6666 \ `let` to deconstruct values only if there is ONE possiblity.\
6767 \ Switch to a `case` expression to account for all possibilities."
68− , H.toSimpleHint $
68+ , D.toSimpleHint $
6969 "Are you calling a function that definitely returns values\
7070 \ with a very specific shape? Try making the return type of\
7171 \ that function more specific!"
@@ -78,12 +78,12 @@ toReport source err =
7878 (
7979 "This `case` does not have branches for all possibilities:"
8080 ,
81− H.stack
81+ D.stack
8282 [ "Missing possibilities include:"
8383 , unhandledPatternsToDocBlock unhandled
84− , H.reflow $
84+ , D.reflow $
8585 "I would have to crash if I saw one of those. Add branches for them!"
86− , H.link "Hint"
86+ , D.link "Hint"
8787 "If you want to write the code for each branch later, use `Debug.todo` as a placeholder. Read"
8888 "missing-patterns"
8989 "for more guidance on this workflow."
@@ -95,9 +95,9 @@ toReport source err =
9595-- PATTERN TO DOC
9696
9797
98−unhandledPatternsToDocBlock :: [P.Pattern] -> H.Doc
98+unhandledPatternsToDocBlock :: [P.Pattern] -> D.Doc
9999unhandledPatternsToDocBlock unhandledPatterns =
100− H.indent 4 $ H.dullyellow $ H.vcat $
100+ D.indent 4 $ D.dullyellow $ D.vcat $
101101 map (patternToDoc Unambiguous) unhandledPatterns
102102
103103
@@ -108,7 +108,7 @@ data Context
108108 deriving (Eq)
109109
110110
111−patternToDoc :: Context -> P.Pattern -> H.Doc
111+patternToDoc :: Context -> P.Pattern -> D.Doc
112112patternToDoc context pattern =
113113 case delist pattern [] of
114114 NonList P.Anything ->
@@ -117,13 +117,13 @@ patternToDoc context pattern =
117117 NonList (P.Literal literal) ->
118118 case literal of
119119 P.Chr chr ->
120− H.textToDoc ("'" <> chr <> "'")
120+ D.fromText ("'" <> chr <> "'")
121121
122122 P.Str str ->
123− H.textToDoc ("\"" <> str <> "\"")
123+ D.fromText ("\"" <> str <> "\"")
124124
125125 P.Int int ->
126− H.text (show int)
126+ D.fromString (show int)
127127
128128 NonList (P.Ctor _ "#0" []) ->
129129 "()"
@@ -142,7 +142,7 @@ patternToDoc context pattern =
142142 NonList (P.Ctor _ name args) ->
143143 let
144144 ctorDoc =
145− H.hsep (H.nameToDoc name : map (patternToDoc Arg) args)
145+ D.hsep (D.fromName name : map (patternToDoc Arg) args)
146146 in
147147 if context == Arg && length args > 0 then
148148 "(" <> ctorDoc <> ")"
@@ -154,7 +154,7 @@ patternToDoc context pattern =
154154
155155 FiniteList entries ->
156156 let entryDocs = map (patternToDoc Unambiguous) entries in
157− "[" <> H.hcat (List.intersperse "," entryDocs) <> "]"
157+ "[" <> D.hcat (List.intersperse "," entryDocs) <> "]"
158158
159159 Conses conses finalPattern ->
160160 let
compiler/src/Reporting/Error/Syntax.hs+65−65
@@ -17,10 +17,10 @@ import qualified Data.Set as Set
1717import qualified Data.Text as Text
1818
1919import qualified Elm.Name as N
20+import qualified Reporting.Doc as D
2021import qualified Reporting.Region as R
2122import qualified Reporting.Render.Code as Code
2223import qualified Reporting.Report as Report
23−import qualified Reporting.Helpers as H
2424
2525
2626
@@ -144,7 +144,7 @@ toReport source err =
144144 (
145145 "This documentation comment is not followed by anything."
146146 ,
147− H.reflow $
147+ D.reflow $
148148 "All documentation comments need to be right above the declaration they\
149149 \ describe. Maybe some code got deleted or commented out by accident? Or\
150150 \ maybe this comment is here by accident?"
@@ -154,12 +154,12 @@ toReport source err =
154154 Report.Report "BAD PORT" region [] $
155155 Report.toCodeSnippet source region Nothing
156156 (
157− H.reflow $
157+ D.reflow $
158158 "You are declaring port `" <> N.toString name <> "` in a normal module."
159159 ,
160− H.stack
160+ D.stack
161161 [ "It needs to be in a `port` module."
162− , H.link "Hint"
162+ , D.link "Hint"
163163 "Ports are not a traditional FFI for calling JS functions directly. They need a different mindset! Read"
164164 "ports"
165165 "to learn how to use ports effectively."
@@ -170,17 +170,17 @@ toReport source err =
170170 Report.Report "ANNOTATION MISMATCH" region [] $
171171 Report.toCodeSnippet source region Nothing
172172 (
173− H.reflow $
173+ D.reflow $
174174 "I see a `" <> N.toString annName
175175 <> "` annotation, but it is followed by a `"
176176 <> N.toString defName <> "` definition."
177177 ,
178− H.fillSep
178+ D.fillSep
179179 ["The","annotation","and","definition","names","must","match!"
180180 ,"Is","there","a","typo","between"
181− , H.dullyellow (H.nameToDoc annName)
181+ , D.dullyellow (D.fromName annName)
182182 ,"and"
183− , H.dullyellow (H.nameToDoc defName) <> "?"
183+ , D.dullyellow (D.fromName defName) <> "?"
184184 ]
185185 )
186186
@@ -188,12 +188,12 @@ toReport source err =
188188 Report.Report "MISSING DEFINITION" region [] $
189189 Report.toCodeSnippet source region Nothing
190190 (
191− H.reflow $
191+ D.reflow $
192192 "There is a type annotation for `" <> N.toString name
193193 <> "` but there is no corresponding definition!"
194194 ,
195195 "Directly below the type annotation, put a definition like:\n\n"
196− <> " " <> H.nameToDoc name <> " = 42"
196+ <> " " <> D.fromName name <> " = 42"
197197 )
198198
199199 Parse region subRegion problem ->
@@ -206,7 +206,7 @@ toReport source err =
206206-- PARSE ERROR TO DOCS
207207
208208
209−problemToDocs :: Problem -> (H.Doc, H.Doc)
209+problemToDocs :: Problem -> (D.Doc, D.Doc)
210210problemToDocs problem =
211211 case problem of
212212 Tab ->
@@ -220,11 +220,11 @@ problemToDocs problem =
220220 (
221221 "I got to the end of the file while parsing a multi-line comment."
222222 ,
223− H.stack
224− [ H.reflow $
223+ D.stack
224+ [ D.reflow $
225225 "Multi-line comments look like {- comment -}, and it looks like\
226226 \ you are missing the closing marker."
227− , H.toSimpleHint $
227+ , D.toSimpleHint $
228228 "Nested multi-line comments like {- this {- and this -} -} are allowed.\
229229 \ The opening and closing markers must be balanced though, just\
230230 \ like parentheses in normal code. Maybe that is the problem?"
@@ -235,7 +235,7 @@ problemToDocs problem =
235235 (
236236 "I got to the end of the file while parsing a GLSL block."
237237 ,
238− H.reflow $
238+ D.reflow $
239239 "A shader should be defined in a block like this: [glsl| ... |]"
240240 )
241241
@@ -243,7 +243,7 @@ problemToDocs problem =
243243 (
244244 "I got to the end of the file while parsing a string."
245245 ,
246− H.reflow $
246+ D.reflow $
247247 "Strings look like \"this\" with double quotes on each end.\
248248 \ Is the closing double quote missing in your code?"
249249 )
@@ -252,7 +252,7 @@ problemToDocs problem =
252252 (
253253 "I got to the end of the file while parsing a multi-line string."
254254 ,
255− H.reflow $
255+ D.reflow $
256256 "Multi-line strings look like \"\"\"this\"\"\" with three double quotes on each\
257257 \ end. Is the closing triple quote missing in your code?"
258258 )
@@ -261,7 +261,7 @@ problemToDocs problem =
261261 (
262262 "I got to the end of the file while parsing a character."
263263 ,
264− H.reflow $
264+ D.reflow $
265265 "Characters look like 'c' with single quotes on each end.\
266266 \ Is the closing single quote missing in your code?"
267267 )
@@ -270,10 +270,10 @@ problemToDocs problem =
270270 (
271271 "This string is missing the closing quote."
272272 ,
273− H.stack
274− [ H.reflow $
273+ D.stack
274+ [ D.reflow $
275275 "Elm strings like \"this\" cannot contain newlines."
276− , H.toSimpleHint $
276+ , D.toSimpleHint $
277277 "For strings that CAN contain newlines, say \"\"\"this\"\"\" for Elm’s\
278278 \ multi-line string syntax. It allows unescaped newlines and double quotes."
279279 ]
@@ -292,10 +292,10 @@ problemToDocs problem =
292292 UnknownEscape ->
293293 (
294294 "Backslashes always start escaped characters, but I do not recognize this one:"
295− , H.stack
295+ , D.stack
296296 [ "Maybe there is some typo?"
297− , H.toSimpleHint "Valid escape characters include:"
298− , H.indent 4 $ H.vcat $
297+ , D.toSimpleHint "Valid escape characters include:"
298+ , D.indent 4 $ D.vcat $
299299 [ "\\n"
300300 , "\\r"
301301 , "\\t"
@@ -304,7 +304,7 @@ problemToDocs problem =
304304 , "\\\\"
305305 , "\\u{03BB}"
306306 ]
307− , H.reflow $
307+ , D.reflow $
308308 "The last one lets encode ANY character by its Unicode code\
309309 \ point, so use that for anything outside the ordinary six."
310310 ]
@@ -314,15 +314,15 @@ problemToDocs problem =
314314 (
315315 "I ran into an invalid Unicode escape character:"
316316 ,
317− H.stack
317+ D.stack
318318 [ "Here are some examples of valid Unicode escape characters:"
319− , H.indent 4 $ H.vcat $
319+ , D.indent 4 $ D.vcat $
320320 [ "\\u{0041}"
321321 , "\\u{03BB}"
322322 , "\\u{6728}"
323323 , "\\u{1F60A}"
324324 ]
325− , H.reflow $
325+ , D.reflow $
326326 "Notice that the code point is always surrounded by curly\
327327 \ braces. They are required!"
328328 ]
@@ -342,18 +342,18 @@ problemToDocs problem =
342342 ,
343343 let
344344 goodCode = replicate (4 - numDigits) '0' ++ badCode
345− escape = "\\u{" <> H.text goodCode <> "}"
345+ escape = "\\u{" <> D.fromString goodCode <> "}"
346346 in
347− H.hsep [ "Try", H.dullyellow escape, "instead?" ]
347+ D.hsep [ "Try", D.dullyellow escape, "instead?" ]
348348 )
349349
350350 else
351351 (
352352 "This Unicode code point has too many digits:"
353353 ,
354− H.fillSep
354+ D.fillSep
355355 ["Valid","code","points","are","between"
356− , H.dullyellow "\\u{0000}", "and", H.dullyellow "\\u{10FFFF}"
356+ , D.dullyellow "\\u{0000}", "and", D.dullyellow "\\u{10FFFF}"
357357 ,"so","it","must","have","between","four","and","six","digits."
358358 ]
359359 )
@@ -362,12 +362,12 @@ problemToDocs problem =
362362 (
363363 "Ran into a bad use of single quotes."
364364 ,
365− H.stack
366− [ H.reflow $
365+ D.stack
366+ [ D.reflow $
367367 "If you want to create a string, switch to double quotes:"
368− , H.indent 4 $
369− H.dullyellow "'this'" <> " => " <> H.green "\"this\""
370− , H.toSimpleHint $
368+ , D.indent 4 $
369+ D.dullyellow "'this'" <> " => " <> D.green "\"this\""
370+ , D.toSimpleHint $
371371 "Unlike JavaScript, Elm distinguishes between strings like \"hello\"\
372372 \ and individual characters like 'A' and '3'. If you really do want\
373373 \ a character though, something went wrong and I did not find the\
@@ -381,16 +381,16 @@ problemToDocs problem =
381381 ,
382382 let
383383 number =
384− H.text (show numberBeforeDot)
384+ D.fromString (show numberBeforeDot)
385385 in
386− "Saying " <> H.green number <> " or " <> H.green (number <> ".0") <> " will work though!"
386+ "Saying " <> D.green number <> " or " <> D.green (number <> ".0") <> " will work though!"
387387 )
388388
389389 BadNumberEnd ->
390390 (
391391 "Numbers cannot have letters or underscores in them."
392392 ,
393− H.reflow $
393+ D.reflow $
394394 "Maybe a space is missing between a number and a variable?"
395395 )
396396
@@ -398,7 +398,7 @@ problemToDocs problem =
398398 (
399399 "If you put the letter E in a number, it should followed by more digits."
400400 ,
401− H.reflow $
401+ D.reflow $
402402 "If you want to say 1000, you can also say 1e3.\
403403 \ You cannot just end it with an E though!"
404404 )
@@ -407,7 +407,7 @@ problemToDocs problem =
407407 (
408408 "I see the start of a hex number, but not the end."
409409 ,
410− H.reflow $
410+ D.reflow $
411411 "A hex number looks like 0x123ABC, where the 0x is followed by hexidecimal\
412412 \ digits. Valid hexidecimal digits include: 0123456789abcdefABCDEF"
413413 )
@@ -416,7 +416,7 @@ problemToDocs problem =
416416 (
417417 "Normal numbers cannot start with zeros. Take the zeros off the front."
418418 ,
419− H.reflow $
419+ D.reflow $
420420 "Only numbers like 0x0040 or 0.25 can start with a zero."
421421 )
422422
@@ -424,7 +424,7 @@ problemToDocs problem =
424424 (
425425 "I cannot pattern match with floating point numbers:"
426426 ,
427− H.reflow $
427+ D.reflow $
428428 "Equality on floats can be unreliable, so you usually want to check that they\
429429 \ are nearby with some sort of (abs (actual - expected) < 0.001) check."
430430 )
@@ -433,14 +433,14 @@ problemToDocs problem =
433433 (
434434 "I ran into a problem while parsing this GLSL block."
435435 ,
436− H.reflow (Text.unpack msg)
436+ D.reflow (Text.unpack msg)
437437 )
438438
439439 BadUnderscore _ ->
440440 (
441441 "A variable name cannot start with an underscore:"
442442 ,
443− H.reflow $
443+ D.reflow $
444444 "You can (1) use a wildcard like _ to ignore the value or you can (2) use\
445445 \ a name that starts with a letter to access the value later. Pick one!"
446446 )
@@ -454,7 +454,7 @@ problemToDocs problem =
454454
455455 Equals ->
456456 (
457− H.reflow $
457+ D.reflow $
458458 "I was not expecting this equals sign"
459459 <> contextToString " here" " while parsing " stack <> "."
460460 ,
@@ -466,7 +466,7 @@ problemToDocs problem =
466466 (
467467 "I ran into a stray arrow while parsing this `case` expression."
468468 ,
469− H.reflow $
469+ D.reflow $
470470 "All branches in a `case` must be indented the exact\
471471 \ same amount, so the patterns are vertically\
472472 \ aligned. Maybe this branch is indented too much?"
@@ -486,7 +486,7 @@ problemToDocs problem =
486486 (
487487 "I was not expecting this dot."
488488 ,
489− H.reflow $
489+ D.reflow $
490490 "Dots are for record access and decimal points, so\
491491 \ they cannot float around on their own. Maybe\
492492 \ there is some extra whitespace?"
@@ -494,27 +494,27 @@ problemToDocs problem =
494494
495495 Theories stack allTheories ->
496496 (
497− H.reflow $
497+ D.reflow $
498498 "Something went wrong while parsing " <> contextToString "your code" "" stack <> "."
499499 ,
500500 case Set.toList (Set.fromList allTheories) of
501501 [] ->
502− H.stack
503− [ H.reflow $
502+ D.stack
503+ [ D.reflow $
504504 "I do not have any suggestions though!"
505− , H.reflow $
505+ , D.reflow $
506506 "Can you get it down to a <http://sscce.org> and share it at\
507507 \ <https://github.com/elm-lang/error-message-catalog/issues>?\
508508 \ That way we can figure out how to give better advice!"
509509 ]
510510
511511 [theory] ->
512− H.reflow $
512+ D.reflow $
513513 "I was expecting to see "
514514 <> addPeriod (theoryToString stack theory)
515515
516516 theories ->
517− H.vcat $
517+ D.vcat $
518518 [ "I was expecting:"
519519 , ""
520520 ]
@@ -526,33 +526,33 @@ problemToDocs problem =
526526-- BAD OP HELPERS
527527
528528
529−badOp :: ContextStack -> String -> String -> String -> String -> ( H.Doc, H.Doc )
529+badOp :: ContextStack -> String -> String -> String -> String -> ( D.Doc, D.Doc )
530530badOp stack article opName setting hint =
531531 (
532− H.reflow $
532+ D.reflow $
533533 "I was not expecting this " <> opName
534534 <> contextToString " here" " while parsing " stack <> "."
535535 ,
536− H.reflow $
536+ D.reflow $
537537 article <> " " <> opName <> " should only appear in "
538538 <> setting <> ". " <> hint
539539 )
540540
541541
542−toBadEqualsHint :: ContextStack -> H.Doc
542+toBadEqualsHint :: ContextStack -> D.Doc
543543toBadEqualsHint stack =
544544 case stack of
545545 [] ->
546− H.reflow $
546+ D.reflow $
547547 "Maybe you want == instead? Or maybe something is indented too much?"
548548
549549 (ExprRecord, _) : _ ->
550− H.reflow $
550+ D.reflow $
551551 "Records look like { x = 3, y = 4 } with the equals sign right\
552552 \ after the field name. Maybe you forgot a comma?"
553553
554554 (Definition _, _) : rest ->
555− H.reflow $
555+ D.reflow $
556556 "Maybe this is supposed to be a separate definition? If so, it\
557557 \ is indented too far. "
558558 <>
@@ -634,9 +634,9 @@ getAnchor stack =
634634-- THEORY HELPERS
635635
636636
637−bullet :: String -> H.Doc
637+bullet :: String -> D.Doc
638638bullet point =
639− H.hang 4 (" - " <> H.fillSep (map H.text (words point)))
639+ D.hang 4 (" - " <> D.fillSep (map D.fromString (words point)))
640640
641641
642642addPeriod :: String -> String
compiler/src/Reporting/Error/Type.hs+251−251
@@ -24,7 +24,7 @@ import Data.Monoid ((<>))
2424
2525import qualified Data.Index as Index
2626import qualified Elm.Name as N
27−import qualified Reporting.Helpers as H
27+import qualified Reporting.Doc as D
2828import qualified Reporting.Region as R
2929import qualified Reporting.Render.Code as Code
3030import qualified Reporting.Render.Type as RT
@@ -202,15 +202,15 @@ toPatternReport source localizer patternRegion category tipe expected =
202202 case context of
203203 PTypedArg name index ->
204204 (
205− H.reflow $
206− "The " <> H.ordinalize (Index.toHuman index) <> " argument to `" <> N.toString name <> "` is weird."
205+ D.reflow $
206+ "The " <> D.ordinalize (Index.toHuman index) <> " argument to `" <> N.toString name <> "` is weird."
207207 ,
208208 patternTypeComparison localizer tipe expectedType
209209 (
210210 toPatternDescription category $
211211 "The argument is a pattern that matches"
212212 ,
213− "But the type annotation on `" <> N.toString name <> "` says the " <> H.ordinalize (Index.toHuman index) <> " argument should be:"
213+ "But the type annotation on `" <> N.toString name <> "` says the " <> D.ordinalize (Index.toHuman index) <> " argument should be:"
214214 ,
215215 []
216216 )
@@ -219,7 +219,7 @@ toPatternReport source localizer patternRegion category tipe expected =
219219 PCaseMatch index ->
220220 if index == Index.first then
221221 (
222− H.reflow $
222+ D.reflow $
223223 "The 1st pattern in this `case` causing a mismatch:"
224224 ,
225225 patternTypeComparison localizer tipe expectedType
@@ -228,20 +228,20 @@ toPatternReport source localizer patternRegion category tipe expected =
228228 ,
229229 "But it is supposed to match an expression of type:"
230230 ,
231− [ H.reflow $
231+ [ D.reflow $
232232 "Is the pattern the problem? Or is it the expression you are trying to match on?"
233233 ]
234234 )
235235 )
236236 else
237237 (
238− H.reflow $
239− "The " <> H.ordinalize (Index.toHuman index) <> " pattern in this `case` does not match the previous ones."
238+ D.reflow $
239+ "The " <> D.ordinalize (Index.toHuman index) <> " pattern in this `case` does not match the previous ones."
240240 ,
241241 patternTypeComparison localizer tipe expectedType
242242 (
243243 toPatternDescription category $
244− "The " <> H.ordinalize (Index.toHuman index) <> " pattern is trying to match"
244+ "The " <> D.ordinalize (Index.toHuman index) <> " pattern is trying to match"
245245 ,
246246 "But all the previous patterns match values of type:"
247247 ,
@@ -251,14 +251,14 @@ toPatternReport source localizer patternRegion category tipe expected =
251251
252252 PCtorArg name index ->
253253 (
254− H.reflow $
255− "The " <> H.ordinalize (Index.toHuman index) <> " argument to `" <> N.toString name <> "` is weird."
254+ D.reflow $
255+ "The " <> D.ordinalize (Index.toHuman index) <> " argument to `" <> N.toString name <> "` is weird."
256256 ,
257257 patternTypeComparison localizer tipe expectedType
258258 (
259259 toPatternDescription category "It is trying to match"
260260 ,
261− "But `" <> N.toString name <> "` needs its " <> H.ordinalize (Index.toHuman index) <> " argument to be:"
261+ "But `" <> N.toString name <> "` needs its " <> D.ordinalize (Index.toHuman index) <> " argument to be:"
262262 ,
263263 []
264264 )
@@ -266,17 +266,17 @@ toPatternReport source localizer patternRegion category tipe expected =
266266
267267 PListEntry index ->
268268 (
269− H.reflow $
270− "The " <> H.ordinalize (Index.toHuman index) <> " pattern in this list does not match all the previous ones:"
269+ D.reflow $
270+ "The " <> D.ordinalize (Index.toHuman index) <> " pattern in this list does not match all the previous ones:"
271271 ,
272272 patternTypeComparison localizer tipe expectedType
273273 (
274274 toPatternDescription category $
275− "The " <> H.ordinalize (Index.toHuman index) <> " pattern is trying to match"
275+ "The " <> D.ordinalize (Index.toHuman index) <> " pattern is trying to match"
276276 ,
277277 "But all the previous patterns in the list are:"
278278 ,
279− [ H.toSimpleHint $
279+ [ D.toSimpleHint $
280280 "Everything in the list needs to be the same type of value.\
281281 \ This way you never run into unexpected values partway through.\
282282 \ To mix different types in a single list, create a \"union type\" as\
@@ -287,7 +287,7 @@ toPatternReport source localizer patternRegion category tipe expected =
287287
288288 PTail ->
289289 (
290− H.reflow $
290+ D.reflow $
291291 "The pattern after (::) is causing issues."
292292 ,
293293 patternTypeComparison localizer tipe expectedType
@@ -306,17 +306,17 @@ toPatternReport source localizer patternRegion category tipe expected =
306306-- PATTERN HELPERS
307307
308308
309−patternTypeComparison :: T.Localizer -> T.Type -> T.Type -> ( String, String, [H.Doc] ) -> H.Doc
309+patternTypeComparison :: T.Localizer -> T.Type -> T.Type -> ( String, String, [D.Doc] ) -> D.Doc
310310patternTypeComparison localizer actual expected ( iAmSeeing, insteadOf, contextHints ) =
311311 let
312312 (actualDoc, expectedDoc, problems) =
313313 T.toDiffDocs localizer actual expected
314314 in
315− H.stack $
316− [ H.reflow iAmSeeing
317− , H.indent 4 actualDoc
318− , H.reflow insteadOf
319− , H.indent 4 expectedDoc
315+ D.stack $
316+ [ D.reflow iAmSeeing
317+ , D.indent 4 actualDoc
318+ , D.reflow insteadOf
319+ , D.indent 4 expectedDoc
320320 ]
321321 ++ problemsToHint problems
322322 ++ contextHints
@@ -340,31 +340,31 @@ toPatternDescription category iAmTryingToMatch =
340340-- EXPR HELPERS
341341
342342
343−typeComparison :: T.Localizer -> T.Type -> T.Type -> ( String, String, [H.Doc] ) -> H.Doc
343+typeComparison :: T.Localizer -> T.Type -> T.Type -> ( String, String, [D.Doc] ) -> D.Doc
344344typeComparison localizer actual expected ( iAmSeeing, insteadOf, contextHints ) =
345345 let
346346 (actualDoc, expectedDoc, problems) =
347347 T.toDiffDocs localizer actual expected
348348 in
349− H.stack $
350− [ H.reflow iAmSeeing
351− , H.indent 4 actualDoc
352− , H.reflow insteadOf
353− , H.indent 4 expectedDoc
349+ D.stack $
350+ [ D.reflow iAmSeeing
351+ , D.indent 4 actualDoc
352+ , D.reflow insteadOf
353+ , D.indent 4 expectedDoc
354354 ]
355355 ++ problemsToHint problems
356356 ++ contextHints
357357
358358
359−loneType :: T.Localizer -> T.Type -> T.Type -> ( H.Doc, [H.Doc] ) -> H.Doc
359+loneType :: T.Localizer -> T.Type -> T.Type -> ( D.Doc, [D.Doc] ) -> D.Doc
360360loneType localizer actual expected ( iAmSeeing, furtherDetails ) =
361361 let
362362 (actualDoc, _, problems) =
363363 T.toDiffDocs localizer actual expected
364364 in
365− H.stack $
365+ D.stack $
366366 [ iAmSeeing
367− , H.indent 4 actualDoc
367+ , D.indent 4 actualDoc
368368 ]
369369 ++ furtherDetails
370370 ++ problemsToHint problems
@@ -398,7 +398,7 @@ toDescription category thatThingIs =
398398 OpName _ -> thatThingIs <> ":"
399399
400400
401−problemsToHint :: [T.Problem] -> [H.Doc]
401+problemsToHint :: [T.Problem] -> [D.Doc]
402402problemsToHint problems =
403403 case problems of
404404 [] ->
@@ -408,63 +408,63 @@ problemsToHint problems =
408408 problemToHint problem
409409
410410
411−problemToHint :: T.Problem -> [H.Doc]
411+problemToHint :: T.Problem -> [D.Doc]
412412problemToHint problem =
413413 case problem of
414414 T.FieldMismatch _ _ -> [] -- TODO do a better job?
415415
416416 T.IntFloat ->
417− [ H.fancyLink "Note" ["Read"] "implicit-casts"
417+ [ D.fancyLink "Note" ["Read"] "implicit-casts"
418418 ["to","learn","why","Elm","does","not","implicitly","convert"
419− ,"Ints","to","Floats.","Use",H.green "toFloat","and"
420− ,H.green "round","to","do","explicit","conversions."
419+ ,"Ints","to","Floats.","Use",D.green "toFloat","and"
420+ ,D.green "round","to","do","explicit","conversions."
421421 ]
422422 ]
423423
424424 T.StringFromInt ->
425− [ H.toFancyHint
425+ [ D.toFancyHint
426426 ["Want","to","convert","an","Int","into","a","String?"
427− ,"Use","the",H.green "String.fromInt","function!"
427+ ,"Use","the",D.green "String.fromInt","function!"
428428 ]
429429 ]
430430
431431 T.StringFromFloat ->
432− [ H.toFancyHint
432+ [ D.toFancyHint
433433 ["Want","to","convert","a","Float","into","a","String?"
434− ,"Use","the",H.green "String.fromFloat","function!"
434+ ,"Use","the",D.green "String.fromFloat","function!"
435435 ]
436436 ]
437437
438438 T.StringToInt ->
439− [ H.toFancyHint
439+ [ D.toFancyHint
440440 ["Want","to","convert","a","String","into","an","Int?"
441− ,"Use","the",H.green "String.toInt","function!"
441+ ,"Use","the",D.green "String.toInt","function!"
442442 ]
443443 ]
444444
445445 T.StringToFloat ->
446− [ H.toFancyHint
446+ [ D.toFancyHint
447447 ["Want","to","convert","a","String","into","a","Float?"
448− ,"Use","the",H.green "String.toFloat","function!"
448+ ,"Use","the",D.green "String.toFloat","function!"
449449 ]
450450 ]
451451
452452 T.AnythingToBool ->
453− [ H.toSimpleHint $
453+ [ D.toSimpleHint $
454454 "Elm does not have “truthiness” such that ints and strings and lists\
455455 \ are automatically converted to booleans. Do that conversion explicitly!"
456456 ]
457457
458458 T.AnythingFromMaybe ->
459− [ H.toFancyHint
460− ["Use",H.green "Maybe.withDefault","to","handle","possible","errors."
459+ [ D.toFancyHint
460+ ["Use",D.green "Maybe.withDefault","to","handle","possible","errors."
461461 ,"Longer","term,","it","is","usually","better","to","write","out","the"
462462 ,"full","`case`","though!"
463463 ]
464464 ]
465465
466466 T.AnythingToList ->
467− [ H.toSimpleHint "Did you forget to add [] around it?"
467+ [ D.toSimpleHint "Did you forget to add [] around it?"
468468 ]
469469
470470 T.MissingArgs _ -> []
@@ -520,25 +520,25 @@ problemToHint problem =
520520-- BAD RIGID HINTS
521521
522522
523−badRigidVar :: N.Name -> String -> [H.Doc]
523+badRigidVar :: N.Name -> String -> [D.Doc]
524524badRigidVar name aThing =
525− [ H.toSimpleHint $
525+ [ D.toSimpleHint $
526526 "Your type annotation uses type variable `" ++ N.toString name ++
527527 "` which means ANY type of value can flow through, but your code is saying it specifically wants "
528528 ++ aThing ++ ". Maybe change your type annotation to\
529529 \ be more specific? Maybe change the code to be more general?"
530− , H.reflowLink "Read" "type-annotations" "for more advice!"
530+ , D.reflowLink "Read" "type-annotations" "for more advice!"
531531 ]
532532
533533
534−badDoubleRigid :: N.Name -> N.Name -> [H.Doc]
534+badDoubleRigid :: N.Name -> N.Name -> [D.Doc]
535535badDoubleRigid x y =
536− [ H.toSimpleHint $
536+ [ D.toSimpleHint $
537537 "Your type annotation uses `" ++ N.toString x ++ "` and `" ++ N.toString y ++
538538 "` as separate type variables. Your code seems to be saying they are the\
539539 \ same though! Maybe they should be the same in your type annotation?\
540540 \ Maybe your code uses them in a weird way?"
541− , H.reflowLink "Read" "type-annotations" "for more advice!"
541+ , D.reflowLink "Read" "type-annotations" "for more advice!"
542542 ]
543543
544544
@@ -555,47 +555,47 @@ toASuperThing super =
555555-- BAD SUPER HINTS
556556
557557
558−badFlexSuper :: T.Super -> T.Type -> [H.Doc]
558+badFlexSuper :: T.Super -> T.Type -> [D.Doc]
559559badFlexSuper super tipe =
560560 case super of
561561 T.Comparable ->
562− [ H.toSimpleHint "Only ints, floats, chars, strings, lists, and tuples are comparable."
562+ [ D.toSimpleHint "Only ints, floats, chars, strings, lists, and tuples are comparable."
563563 ]
564564
565565 T.Appendable ->
566566 case tipe of
567567 T.Type home name _ | T.isInt home name ->
568− [ H.toFancyHint ["Try","using",H.green"String.fromInt","to","convert","it","to","a","string?"]
568+ [ D.toFancyHint ["Try","using",D.green"String.fromInt","to","convert","it","to","a","string?"]
569569 ]
570570
571571 T.Type home name _ | T.isFloat home name ->
572− [ H.toFancyHint ["Try","using",H.green"String.fromFloat","to","convert","it","to","a","string?"]
572+ [ D.toFancyHint ["Try","using",D.green"String.fromFloat","to","convert","it","to","a","string?"]
573573 ]
574574
575575 T.FlexSuper T.Number _ ->
576− [ H.toFancyHint ["Try","using",H.green"String.fromInt","to","convert","it","to","a","string?"]
576+ [ D.toFancyHint ["Try","using",D.green"String.fromInt","to","convert","it","to","a","string?"]
577577 ]
578578
579579 _ ->
580− [ H.toFancyHint ["Only","strings","and","lists","are","appendable.","Put","it","in",H.green "[]","to","make","it","a","list?"]
580+ [ D.toFancyHint ["Only","strings","and","lists","are","appendable.","Put","it","in",D.green "[]","to","make","it","a","list?"]
581581 ]
582582
583583 T.CompAppend ->
584− [ H.toSimpleHint "Only strings and lists are both comparable and appendable."
584+ [ D.toSimpleHint "Only strings and lists are both comparable and appendable."
585585 ]
586586
587587 T.Number ->
588588 case tipe of
589589 T.Type home name _ | T.isString home name ->
590− [ H.toFancyHint ["Try","using",H.green"String.toInt","to","convert","it","to","a","number?"]
590+ [ D.toFancyHint ["Try","using",D.green"String.toInt","to","convert","it","to","a","number?"]
591591 ]
592592
593593 _ ->
594− [ H.toFancyHint ["Only",H.green "Int","and",H.green "Float","values","work","as","numbers."]
594+ [ D.toFancyHint ["Only",D.green "Int","and",D.green "Float","values","work","as","numbers."]
595595 ]
596596
597597
598−badRigidSuper :: T.Super -> String -> [H.Doc]
598+badRigidSuper :: T.Super -> String -> [D.Doc]
599599badRigidSuper super aThing =
600600 let
601601 (superType, manyThings) =
@@ -605,16 +605,16 @@ badRigidSuper super aThing =
605605 T.Appendable -> ("appendable", "strings AND lists")
606606 T.CompAppend -> ("compappend", "strings AND lists")
607607 in
608− [ H.toSimpleHint $
608+ [ D.toSimpleHint $
609609 "The `" ++ superType ++ "` in your type annotation is saying that "
610610 ++ manyThings ++ " can flow through, but your code is saying it specifically wants "
611611 ++ aThing ++ ". Maybe change your type annotation to\
612612 \ be more specific? Maybe change the code to be more general?"
613− , H.reflowLink "Read" "type-annotations" "for more advice!"
613+ , D.reflowLink "Read" "type-annotations" "for more advice!"
614614 ]
615615
616616
617−badFlexFlexSuper :: T.Super -> T.Super -> [H.Doc]
617+badFlexFlexSuper :: T.Super -> T.Super -> [D.Doc]
618618badFlexFlexSuper s1 s2 =
619619 let
620620 likeThis super =
@@ -624,7 +624,7 @@ badFlexFlexSuper s1 s2 =
624624 T.CompAppend -> "a compappend"
625625 T.Appendable -> "appendable"
626626 in
627− [ H.toSimpleHint $
627+ [ D.toSimpleHint $
628628 "There are no values in Elm that are both"
629629 ++ likeThis s1 ++ " and " ++ likeThis s2 ++ "."
630630 ]
@@ -656,13 +656,13 @@ toExprReport source localizer exprRegion category tipe expected =
656656 FromAnnotation name _arity subContext expectedType ->
657657 Report.toCodeSnippet source exprRegion Nothing
658658 (
659− H.reflow $
659+ D.reflow $
660660 case subContext of
661661 TypedIfBranch index ->
662− "Something is off with the " <> H.ordinalize (Index.toHuman index) <> " branch of this `if` expression:"
662+ "Something is off with the " <> D.ordinalize (Index.toHuman index) <> " branch of this `if` expression:"
663663
664664 TypedCaseBranch index ->
665− "Something is off with the " <> H.ordinalize (Index.toHuman index) <> " branch of this `case` expression:"
665+ "Something is off with the " <> D.ordinalize (Index.toHuman index) <> " branch of this `case` expression:"
666666
667667 TypedBody ->
668668 "Something is off with the body of the `" <> N.toString name <> "` definition:"
@@ -672,10 +672,10 @@ toExprReport source localizer exprRegion category tipe expected =
672672 toDescription category $
673673 case subContext of
674674 TypedIfBranch index ->
675− "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
675+ "The " <> D.ordinalize (Index.toHuman index) <> " branch is"
676676
677677 TypedCaseBranch index ->
678− "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
678+ "The " <> D.ordinalize (Index.toHuman index) <> " branch is"
679679
680680 TypedBody ->
681681 "The body is"
@@ -691,17 +691,17 @@ toExprReport source localizer exprRegion category tipe expected =
691691 ListEntry index ->
692692 Report.toCodeSnippet source region (Just exprRegion)
693693 (
694− H.reflow $
695− "The " <> H.ordinalize (Index.toHuman index) <> " element of this list does not match all the previous elements:"
694+ D.reflow $
695+ "The " <> D.ordinalize (Index.toHuman index) <> " element of this list does not match all the previous elements:"
696696 ,
697697 typeComparison localizer tipe expectedType
698698 (
699699 toDescription category $
700− "The " <> H.ordinalize (Index.toHuman index) <> " element is"
700+ "The " <> D.ordinalize (Index.toHuman index) <> " element is"
701701 ,
702702 "But all the previous elements in the list are:"
703703 ,
704− [ H.toSimpleHint $
704+ [ D.toSimpleHint $
705705 "Everything in the list needs to be the same type of value.\
706706 \ This way you never run into unexpected values partway through.\
707707 \ To mix different types in a single list, create a \"union type\" as\
@@ -717,11 +717,11 @@ toExprReport source localizer exprRegion category tipe expected =
717717 ,
718718 loneType localizer tipe expectedType
719719 (
720− H.reflow $ toDescription category "It is"
720+ D.reflow $ toDescription category "It is"
721721 ,
722− [ H.fillSep
722+ [ D.fillSep
723723 ["But","I","only","now","how","to","negate"
724− ,H.dullyellow "Int","and",H.dullyellow "Float","values."
724+ ,D.dullyellow "Int","and",D.dullyellow "Float","values."
725725 ]
726726 ]
727727 )
@@ -746,9 +746,9 @@ toExprReport source localizer exprRegion category tipe expected =
746746 ,
747747 loneType localizer tipe expectedType
748748 (
749− H.reflow $ toDescription category "It is"
749+ D.reflow $ toDescription category "It is"
750750 ,
751− [ H.fillSep ["But","I","need","this","`if`","condition","to","be","a",H.dullyellow "Bool","value."]
751+ [ D.fillSep ["But","I","need","this","`if`","condition","to","be","a",D.dullyellow "Bool","value."]
752752 ]
753753 )
754754 )
@@ -756,17 +756,17 @@ toExprReport source localizer exprRegion category tipe expected =
756756 IfBranch index ->
757757 Report.toCodeSnippet source region (Just exprRegion)
758758 (
759− H.reflow $
760− "The " <> H.ordinalize (Index.toHuman index) <> " branch of this `if` does not match all the previous branches:"
759+ D.reflow $
760+ "The " <> D.ordinalize (Index.toHuman index) <> " branch of this `if` does not match all the previous branches:"
761761 ,
762762 typeComparison localizer tipe expectedType
763763 (
764764 toDescription category $
765− "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
765+ "The " <> D.ordinalize (Index.toHuman index) <> " branch is"
766766 ,
767767 "But all the previous branches result in:"
768768 ,
769− [ H.link "Hint"
769+ [ D.link "Hint"
770770 "All branches in an `if` must produce the same type of values. This way, no\
771771 \ matter which branch we take, the result is always a consistent shape. Read"
772772 "union-types"
@@ -778,17 +778,17 @@ toExprReport source localizer exprRegion category tipe expected =
778778 CaseBranch index ->
779779 Report.toCodeSnippet source region (Just exprRegion)
780780 (
781− H.reflow $
782− "The " <> H.ordinalize (Index.toHuman index) <> " branch of this `case` does not match all the previous branches:"
781+ D.reflow $
782+ "The " <> D.ordinalize (Index.toHuman index) <> " branch of this `case` does not match all the previous branches:"
783783 ,
784784 typeComparison localizer tipe expectedType
785785 (
786786 toDescription category $
787− "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
787+ "The " <> D.ordinalize (Index.toHuman index) <> " branch is"
788788 ,
789789 "But all the previous branches result in:"
790790 ,
791− [ H.link "Hint"
791+ [ D.link "Hint"
792792 "All branches in a `case` must produce the same type of values. This way, no\
793793 \ matter which branch we take, the result is always a consistent shape. Read"
794794 "union-types"
@@ -801,33 +801,33 @@ toExprReport source localizer exprRegion category tipe expected =
801801 case countArgs tipe of
802802 0 ->
803803 Report.toCodeSnippet source region (Just exprRegion)
804− ( H.reflow $
804+ ( D.reflow $
805805 case maybeFuncName of
806806 NoName -> "This is not a function:"
807807 FuncName name -> "The `" <> N.toString name <> "` value is not a function:"
808808 CtorName name -> "The `" <> N.toString name <> "` value is not a function:"
809809 OpName op -> "The (" <> N.toString op <> ") operator is not a function:"
810810 ,
811− H.stack $
811+ D.stack $
812812 [ "It has type:"
813− , H.indent 4 $ H.dullyellow $ T.toDoc localizer RT.None tipe
814− , H.reflow $ "So it cannot accept arguments, but it got " <> show numArgs <> " anyway."
813+ , D.indent 4 $ D.dullyellow $ T.toDoc localizer RT.None tipe
814+ , D.reflow $ "So it cannot accept arguments, but it got " <> show numArgs <> " anyway."
815815 ]
816816 )
817817
818818 n ->
819819 Report.toCodeSnippet source region (Just exprRegion)
820− ( H.reflow $
820+ ( D.reflow $
821821 case maybeFuncName of
822822 NoName -> "This function was given too many arguments:"
823823 FuncName name -> "The `" <> N.toString name <> "` function was given too many arguments:"
824824 CtorName name -> "The `" <> N.toString name <> "` constructor was given too many arguments:"
825825 OpName op -> "The (" <> N.toString op <> ") operator was given too many arguments:"
826826 ,
827− H.stack $
827+ D.stack $
828828 [ "It has type:"
829− , H.indent 4 $ H.dullyellow $ T.toDoc localizer RT.None tipe
830− , H.reflow $ "So it expects " <> H.args n <> ", but it got " <> show numArgs <> " instead."
829+ , D.indent 4 $ D.dullyellow $ T.toDoc localizer RT.None tipe
830+ , D.reflow $ "So it expects " <> D.args n <> ", but it got " <> show numArgs <> " instead."
831831 ]
832832 )
833833
@@ -842,20 +842,20 @@ toExprReport source localizer exprRegion category tipe expected =
842842 in
843843 Report.toCodeSnippet source region (Just exprRegion)
844844 (
845− H.reflow $
846− "The " <> H.ordinalize (Index.toHuman index) <> " argument to " <> thisFunction <> " is not what I expect:"
845+ D.reflow $
846+ "The " <> D.ordinalize (Index.toHuman index) <> " argument to " <> thisFunction <> " is not what I expect:"
847847 ,
848848 typeComparison localizer tipe expectedType
849849 (
850850 toDescription category "This argument is"
851851 ,
852− "But " <> thisFunction <> " needs the " <> H.ordinalize (Index.toHuman index)
852+ "But " <> thisFunction <> " needs the " <> D.ordinalize (Index.toHuman index)
853853 <> " argument to be:"
854854 ,
855855 if Index.toHuman index == 1 then
856856 []
857857 else
858− [ H.toSimpleHint $
858+ [ D.toSimpleHint $
859859 "I always figure out the argument types from left to right. If an argument\
860860 \ is acceptable, I assume it is “correct” and move on. So the problem may\
861861 \ actually be in one of the previous arguments!"
@@ -868,19 +868,19 @@ toExprReport source localizer exprRegion category tipe expected =
868868 0 ->
869869 Report.toCodeSnippet source region (Just exprRegion)
870870 (
871− H.reflow $
871+ D.reflow $
872872 case maybeName of
873873 NoName ->
874− "You are giving " <> H.args numGivenArgs <> " to something that is not a function!"
874+ "You are giving " <> D.args numGivenArgs <> " to something that is not a function!"
875875
876876 FuncName name ->
877− "`" <> N.toString name <> "` is not a function, but you are giving it " <> H.args numGivenArgs <> "!"
877+ "`" <> N.toString name <> "` is not a function, but you are giving it " <> D.args numGivenArgs <> "!"
878878
879879 CtorName name ->
880− "`" <> N.toString name <> "` is not a function, but you are giving it " <> H.args numGivenArgs <> "!"
880+ "`" <> N.toString name <> "` is not a function, but you are giving it " <> D.args numGivenArgs <> "!"
881881
882882 OpName op ->
883− "(" <> N.toString op <> ") is not a function, but you are giving it " <> H.args numGivenArgs <> "!"
883+ "(" <> N.toString op <> ") is not a function, but you are giving it " <> D.args numGivenArgs <> "!"
884884 ,
885885 typeComparison localizer tipe expectedType
886886 (
@@ -897,7 +897,7 @@ toExprReport source localizer exprRegion category tipe expected =
897897 OpName op ->
898898 "(" <> N.toString op <> ") is a value of type:"
899899 ,
900− "But you are giving it " <> H.args numGivenArgs <> " as if its type was:"
900+ "But you are giving it " <> D.args numGivenArgs <> " as if its type was:"
901901 ,
902902 [ "Maybe you forgot some parentheses? Or a comma?"
903903 ]
@@ -922,17 +922,17 @@ toExprReport source localizer exprRegion category tipe expected =
922922 in
923923 Report.toCodeSnippet source region (Just exprRegion)
924924 (
925− H.reflow $
925+ D.reflow $
926926 thisFunction <> " is getting too many arguments:"
927927 ,
928928 typeComparison localizer tipe expectedType
929929 (
930− thisFunction <> " is expecting to get " <> H.args numExpectedArgs <> " like this:"
930+ thisFunction <> " is expecting to get " <> D.args numExpectedArgs <> " like this:"
931931 ,
932− "But you are giving it " <> H.args numGivenArgs <> " as if its type was:"
932+ "But you are giving it " <> D.args numGivenArgs <> " as if its type was:"
933933 ,
934934 [ "Maybe you forgot some parentheses? Or a comma?"
935− , H.toSimpleNote $
935+ , D.toSimpleNote $
936936 "I am not good at figuring out which arguments are extra myself. The\
937937 \ problem may even be that the FUNCTION is defined funny, and the arguments are\
938938 \ actually fine. Anyway, I hope I gave enough info to help you figure it out!"
@@ -945,15 +945,15 @@ toExprReport source localizer exprRegion category tipe expected =
945945 case tipe of
946946 T.Record _ _ ->
947947 (
948− H.reflow $
948+ D.reflow $
949949 "This record does not have a `" <> N.toString field <> "` field:"
950950 ,
951951 loneType localizer tipe expectedType
952952 (
953− H.reflow $ "It is a record with this type:"
953+ D.reflow $ "It is a record with this type:"
954954 ,
955− [ H.fillSep
956− ["Is","the",H.dullyellow ("." <> H.nameToDoc field)
955+ [ D.fillSep
956+ ["Is","the",D.dullyellow ("." <> D.fromName field)
957957 ,"field","access","is","misspelled?"
958958 ]
959959 ]
@@ -962,14 +962,14 @@ toExprReport source localizer exprRegion category tipe expected =
962962
963963 _ ->
964964 (
965− H.reflow $
965+ D.reflow $
966966 "This is not a record, so it has no fields to access!"
967967 ,
968968 loneType localizer tipe expectedType
969− ( H.reflow $ toDescription category "It is"
970− , [ H.fillSep
969+ ( D.reflow $ toDescription category "It is"
970+ , [ D.fillSep
971971 ["But","I","need","a","record","with","a"
972− ,H.dullyellow (H.nameToDoc field),"field!"
972+ ,D.dullyellow (D.fromName field),"field!"
973973 ]
974974 ]
975975 )
@@ -980,7 +980,7 @@ toExprReport source localizer exprRegion category tipe expected =
980980 T.Record _ _ ->
981981 Report.toCodeSnippet source region Nothing $
982982 (
983− H.reflow $
983+ D.reflow $
984984 "I think there is a typo in one of these field names:"
985985 ,
986986 typeComparison localizer tipe expectedType
@@ -989,7 +989,7 @@ toExprReport source localizer exprRegion category tipe expected =
989989 ,
990990 "But you are saying it should have these fields:"
991991 ,
992− [ H.reflow "Maybe there is some typo?"
992+ [ D.reflow "Maybe there is some typo?"
993993 ]
994994 )
995995 )
@@ -1000,8 +1000,8 @@ toExprReport source localizer exprRegion category tipe expected =
10001000 "The record update syntax does not work with this value:"
10011001 ,
10021002 loneType localizer tipe expectedType
1003− ( H.reflow $ toDescription category "It is"
1004− , [ H.reflow $ "But I need some kind of record here!"
1003+ ( D.reflow $ toDescription category "It is"
1004+ , [ D.reflow $ "But I need some kind of record here!"
10051005 ]
10061006 )
10071007 )
@@ -1009,7 +1009,7 @@ toExprReport source localizer exprRegion category tipe expected =
10091009 Destructure ->
10101010 Report.toCodeSnippet source region Nothing
10111011 (
1012− H.reflow $
1012+ D.reflow $
10131013 "I cannot destructure "
10141014 ,
10151015 typeComparison localizer tipe expectedType
@@ -1041,7 +1041,7 @@ countArgs tipe =
10411041-- OP LEFT
10421042
10431043
1044−opLeftToDocs :: T.Localizer -> Category -> N.Name -> T.Type -> T.Type -> (H.Doc, H.Doc)
1044+opLeftToDocs :: T.Localizer -> Category -> N.Name -> T.Type -> T.Type -> (D.Doc, D.Doc)
10451045opLeftToDocs localizer category op tipe expected =
10461046 case op of
10471047 "+"
@@ -1070,15 +1070,15 @@ opLeftToDocs localizer category op tipe expected =
10701070 ( "The left side of (<|) needs to be a function so I can pipe arguments to it!"
10711071 ,
10721072 loneType localizer tipe expected
1073− ( H.reflow $ toDescription category "I am seeing"
1074− , [ H.reflow $ "This needs to be some kind of function though!"
1073+ ( D.reflow $ toDescription category "I am seeing"
1074+ , [ D.reflow $ "This needs to be some kind of function though!"
10751075 ]
10761076 )
10771077 )
10781078
10791079 _ ->
10801080 (
1081− H.reflow $
1081+ D.reflow $
10821082 "The left argument of (" <> N.toString op <> ") is causing problems:"
10831083 ,
10841084 typeComparison localizer tipe expected
@@ -1097,8 +1097,8 @@ opLeftToDocs localizer category op tipe expected =
10971097
10981098
10991099data RightDocs
1100− = EmphBoth (H.Doc, H.Doc)
1101− | EmphRight (H.Doc, H.Doc)
1100+ = EmphBoth (D.Doc, D.Doc)
1101+ | EmphRight (D.Doc, D.Doc)
11021102
11031103
11041104opRightToDocs :: T.Localizer -> Category -> N.Name -> T.Type -> T.Type -> RightDocs
@@ -1146,7 +1146,7 @@ opRightToDocs localizer category op tipe expected =
11461146 "<|" ->
11471147 EmphRight
11481148 (
1149− H.reflow $
1149+ D.reflow $
11501150 "I cannot send this through the (<|) pipe:"
11511151 ,
11521152 typeComparison localizer tipe expected
@@ -1182,7 +1182,7 @@ opRightToDocs localizer category op tipe expected =
11821182 "The right side of (|>) needs to be a function so I can pipe arguments to it!"
11831183 ,
11841184 loneType localizer tipe expected
1185− ( H.reflow $ toDescription category $
1185+ ( D.reflow $ toDescription category $
11861186 "But instead of a function, I am seeing "
11871187 , []
11881188 )
@@ -1196,7 +1196,7 @@ badOpRightFallback :: T.Localizer -> Category -> N.Name -> T.Type -> T.Type -> R
11961196badOpRightFallback localizer category op tipe expected =
11971197 EmphRight
11981198 (
1199− H.reflow $
1199+ D.reflow $
12001200 "The right argument of (" <> N.toString op <> ") is causing problems."
12011201 ,
12021202 typeComparison localizer tipe expected
@@ -1205,7 +1205,7 @@ badOpRightFallback localizer category op tipe expected =
12051205 ,
12061206 "But (" <> N.toString op <> ") needs the right argument to be:"
12071207 ,
1208− [ H.toSimpleHint $
1208+ [ D.toSimpleHint $
12091209 "With operators like (" ++ N.toString op ++ ") I always check the left\
12101210 \ side first. If it seems fine, I assume it is correct and check the right\
12111211 \ side. So the problem may be in how the left and right arguments interact!"
@@ -1266,7 +1266,7 @@ badConsRight localizer category tipe expected =
12661266 T.Type home2 name2 [expectedElement] | T.isList home2 name2 ->
12671267 EmphBoth
12681268 (
1269− H.reflow "I am having trouble with this (::) operator:"
1269+ D.reflow "I am having trouble with this (::) operator:"
12701270 ,
12711271 typeComparison localizer expectedElement actualElement
12721272 (
@@ -1276,14 +1276,14 @@ badConsRight localizer category tipe expected =
12761276 ,
12771277 case expectedElement of
12781278 T.Type home name [_] | T.isList home name ->
1279− [ H.toSimpleHint
1279+ [ D.toSimpleHint
12801280 "Are you trying to append two lists? The (++) operator\
12811281 \ appends lists, whereas the (::) operator is only for\
12821282 \ adding ONE element to a list."
12831283 ]
12841284
12851285 _ ->
1286− [ H.reflow
1286+ [ D.reflow
12871287 "Lists need ALL elements to be the same type though."
12881288 ]
12891289 )
@@ -1295,13 +1295,13 @@ badConsRight localizer category tipe expected =
12951295 _ ->
12961296 EmphRight
12971297 (
1298− H.reflow "The (::) operator can only add elements onto lists."
1298+ D.reflow "The (::) operator can only add elements onto lists."
12991299 ,
13001300 loneType localizer tipe expected
13011301 (
1302− H.reflow $ toDescription category "The right side is"
1302+ D.reflow $ toDescription category "The right side is"
13031303 ,
1304− [H.fillSep ["But","(::)","needs","a",H.dullyellow "List","on","the","right."]
1304+ [D.fillSep ["But","(::)","needs","a",D.dullyellow "List","on","the","right."]
13051305 ]
13061306 )
13071307 )
@@ -1312,7 +1312,7 @@ badConsRight localizer category tipe expected =
13121312
13131313
13141314data AppendType
1315− = ANumber H.Doc H.Doc
1315+ = ANumber D.Doc D.Doc
13161316 | AString
13171317 | AList
13181318 | AOther
@@ -1332,18 +1332,18 @@ toAppendType tipe =
13321332 _ -> AOther
13331333
13341334
1335−badAppendLeft :: T.Localizer -> Category -> T.Type -> T.Type -> (H.Doc, H.Doc)
1335+badAppendLeft :: T.Localizer -> Category -> T.Type -> T.Type -> (D.Doc, D.Doc)
13361336badAppendLeft localizer category tipe expected =
13371337 case toAppendType tipe of
13381338 ANumber thing stringFromThing ->
13391339 (
1340− H.fillSep
1340+ D.fillSep
13411341 ["The","(++)","operator","can","append","List","and","String"
1342− ,"values,","but","not",H.dullyellow thing,"values","like","this:"
1342+ ,"values,","but","not",D.dullyellow thing,"values","like","this:"
13431343 ]
13441344 ,
1345− H.fillSep
1346− ["Try","using",H.green stringFromThing,"to","turn","it","into","a","string?"
1345+ D.fillSep
1346+ ["Try","using",D.green stringFromThing,"to","turn","it","into","a","string?"
13471347 ,"Or","put","it","in","[]","to","make","it","a","list?"
13481348 ,"Or","switch","to","the","(::)","operator?"
13491349 ]
@@ -1351,15 +1351,15 @@ badAppendLeft localizer category tipe expected =
13511351
13521352 _ ->
13531353 (
1354− H.reflow $
1354+ D.reflow $
13551355 "The (++) operator cannot append this type of value:"
13561356 ,
13571357 loneType localizer tipe expected
1358− ( H.reflow $ toDescription category "I am seeing"
1358+ ( D.reflow $ toDescription category "I am seeing"
13591359 ,
1360− [ H.fillSep
1360+ [ D.fillSep
13611361 ["But","the","(++)","operator","is","only","for","appending"
1362− ,H.dullyellow "List","and",H.dullyellow "String","values."
1362+ ,D.dullyellow "List","and",D.dullyellow "String","values."
13631363 ,"Maybe","put","this","value","in","[]","to","make","it","a","list?"
13641364 ]
13651365 ]
@@ -1373,13 +1373,13 @@ badAppendRight localizer category tipe expected =
13731373 (AString, ANumber thing stringFromThing) ->
13741374 EmphRight
13751375 (
1376− H.fillSep
1377− ["I","thought","I","was","appending",H.dullyellow "String","values","here,"
1378− ,"not",H.dullyellow thing,"values","like","this:"
1376+ D.fillSep
1377+ ["I","thought","I","was","appending",D.dullyellow "String","values","here,"
1378+ ,"not",D.dullyellow thing,"values","like","this:"
13791379 ]
13801380 ,
1381− H.fillSep
1382− ["Try","using",H.green stringFromThing
1381+ D.fillSep
1382+ ["Try","using",D.green stringFromThing
13831383 ,"to","turn","it","into","a","string?"
13841384 ]
13851385 )
@@ -1387,23 +1387,23 @@ badAppendRight localizer category tipe expected =
13871387 (AList, ANumber thing _) ->
13881388 EmphRight
13891389 (
1390− H.fillSep
1391− ["I","thought","I","was","appending",H.dullyellow "List","values","here,"
1392− ,"not",H.dullyellow thing,"values","like","this:"
1390+ D.fillSep
1391+ ["I","thought","I","was","appending",D.dullyellow "List","values","here,"
1392+ ,"not",D.dullyellow thing,"values","like","this:"
13931393 ]
13941394 ,
1395− H.reflow "Try putting it in [] to make it a list?"
1395+ D.reflow "Try putting it in [] to make it a list?"
13961396 )
13971397
13981398 (AString, AList) ->
13991399 EmphBoth
14001400 (
1401− H.reflow $
1401+ D.reflow $
14021402 "The (++) operator needs the same type of value on both sides:"
14031403 ,
1404− H.fillSep
1405− ["I","see","a",H.dullyellow "String","on","the","left","and","a"
1406− ,H.dullyellow "List","on","the","right.","Which","should","it","be?"
1404+ D.fillSep
1405+ ["I","see","a",D.dullyellow "String","on","the","left","and","a"
1406+ ,D.dullyellow "List","on","the","right.","Which","should","it","be?"
14071407 ,"Does","the","string","need","[]","around","it","to","become","a","list?"
14081408 ]
14091409 )
@@ -1411,12 +1411,12 @@ badAppendRight localizer category tipe expected =
14111411 (AList, AString) ->
14121412 EmphBoth
14131413 (
1414− H.reflow $
1414+ D.reflow $
14151415 "The (++) operator needs the same type of value on both sides:"
14161416 ,
1417− H.fillSep
1418− ["I","see","a",H.dullyellow "List","on","the","left","and","a"
1419− ,H.dullyellow "String","on","the","right.","Which","should","it","be?"
1417+ D.fillSep
1418+ ["I","see","a",D.dullyellow "List","on","the","left","and","a"
1419+ ,D.dullyellow "String","on","the","right.","Which","should","it","be?"
14201420 ,"Does","the","string","need","[]","around","it","to","become","a","list?"
14211421 ]
14221422 )
@@ -1424,7 +1424,7 @@ badAppendRight localizer category tipe expected =
14241424 (_,_) ->
14251425 EmphBoth
14261426 (
1427− H.reflow $
1427+ D.reflow $
14281428 "The (++) operator cannot append these two values:"
14291429 ,
14301430 typeComparison localizer expected tipe
@@ -1450,14 +1450,14 @@ badCast :: N.Name -> ThisThenThat -> RightDocs
14501450badCast op thisThenThat =
14511451 EmphBoth
14521452 (
1453− H.text $
1453+ D.reflow $
14541454 "I need both sides of (" <> N.toString op <> ") to be the exact same type. Both Int or both Float."
14551455 ,
14561456 let
1457− anInt = ["an", H.dullyellow "Int"]
1458− aFloat = ["a", H.dullyellow "Float"]
1459− toFloat = H.green "toFloat"
1460− round = H.green "round"
1457+ anInt = ["an", D.dullyellow "Int"]
1458+ aFloat = ["a", D.dullyellow "Float"]
1459+ toFloat = D.green "toFloat"
1460+ round = D.green "round"
14611461 in
14621462 case thisThenThat of
14631463 FloatInt ->
@@ -1468,85 +1468,85 @@ badCast op thisThenThat =
14681468 )
14691469
14701470
1471−badCastHelp :: [H.Doc] -> [H.Doc] -> H.Doc -> H.Doc -> H.Doc
1471+badCastHelp :: [D.Doc] -> [D.Doc] -> D.Doc -> D.Doc -> D.Doc
14721472badCastHelp anInt aFloat toFloat round =
1473− H.stack
1474− [ H.fillSep $
1473+ D.stack
1474+ [ D.fillSep $
14751475 ["But","I","see"]
14761476 ++ anInt
14771477 ++ ["on","the","left","and"]
14781478 ++ aFloat
14791479 ++ ["on","the","right."]
1480− , H.fillSep
1480+ , D.fillSep
14811481 ["Use",toFloat,"on","the","left","(or",round,"on"
14821482 ,"the","right)","to","make","both","sides","match!"
14831483 ]
1484− , H.link "Note" "Read" "implicit-casts" "to learn why Elm does not implicitly convert Ints to Floats."
1484+ , D.link "Note" "Read" "implicit-casts" "to learn why Elm does not implicitly convert Ints to Floats."
14851485 ]
14861486
14871487
1488−badStringAdd :: (H.Doc, H.Doc)
1488+badStringAdd :: (D.Doc, D.Doc)
14891489badStringAdd =
14901490 (
1491− H.fillSep ["I","cannot","do","addition","with",H.dullyellow "String","values","like","this","one:"]
1491+ D.fillSep ["I","cannot","do","addition","with",D.dullyellow "String","values","like","this","one:"]
14921492 ,
1493− H.stack
1494− [ H.fillSep
1495− ["The","(+)","operator","only","works","with",H.dullyellow "Int","and",H.dullyellow "Float","values."
1493+ D.stack
1494+ [ D.fillSep
1495+ ["The","(+)","operator","only","works","with",D.dullyellow "Int","and",D.dullyellow "Float","values."
14961496 ]
1497− , H.toFancyHint
1498− ["Switch","to","the",H.green "(++)","operator","to","append","strings!"
1497+ , D.toFancyHint
1498+ ["Switch","to","the",D.green "(++)","operator","to","append","strings!"
14991499 ]
15001500 ]
15011501 )
15021502
15031503
1504−badListAdd :: T.Localizer -> Category -> String -> T.Type -> T.Type -> (H.Doc, H.Doc)
1504+badListAdd :: T.Localizer -> Category -> String -> T.Type -> T.Type -> (D.Doc, D.Doc)
15051505badListAdd localizer category direction tipe expected =
15061506 (
15071507 "I cannot do addition with lists:"
15081508 ,
15091509 loneType localizer tipe expected
15101510 (
1511− H.reflow $ toDescription category $
1511+ D.reflow $ toDescription category $
15121512 "The " <> direction <> " side of (+) is"
15131513 ,
1514− [ H.fillSep
1515− ["But","(+)","only","works","with",H.dullyellow "Int","and",H.dullyellow "Float","values."
1514+ [ D.fillSep
1515+ ["But","(+)","only","works","with",D.dullyellow "Int","and",D.dullyellow "Float","values."
15161516 ]
1517− , H.toFancyHint
1518− ["Switch","to","the",H.green "(++)","operator","to","append","lists!"
1517+ , D.toFancyHint
1518+ ["Switch","to","the",D.green "(++)","operator","to","append","lists!"
15191519 ]
15201520 ]
15211521 )
15221522 )
15231523
15241524
1525−badListMul :: T.Localizer -> Category -> String -> T.Type -> T.Type -> (H.Doc, H.Doc)
1525+badListMul :: T.Localizer -> Category -> String -> T.Type -> T.Type -> (D.Doc, D.Doc)
15261526badListMul localizer category direction tipe expected =
15271527 badMath localizer category "Multiplication" direction "*" tipe expected
15281528 [
1529− H.toFancyHint
1529+ D.toFancyHint
15301530 [ "Maybe", "you", "want"
1531− , H.green "List.repeat"
1531+ , D.green "List.repeat"
15321532 , "to", "build","a","list","of","repeated","values?"
15331533 ]
15341534 ]
15351535
15361536
1537−badMath :: T.Localizer -> Category -> String -> String -> String -> T.Type -> T.Type -> [H.Doc] -> (H.Doc, H.Doc)
1537+badMath :: T.Localizer -> Category -> String -> String -> String -> T.Type -> T.Type -> [D.Doc] -> (D.Doc, D.Doc)
15381538badMath localizer category operation direction op tipe expected otherHints =
15391539 (
1540− H.reflow $
1540+ D.reflow $
15411541 operation ++ " does not work with this value:"
15421542 ,
15431543 loneType localizer tipe expected
1544− ( H.reflow $ toDescription category $
1544+ ( D.reflow $ toDescription category $
15451545 "The " <> direction <> " side of (" <> op <> ") is"
15461546 ,
1547− [ H.fillSep
1548− ["But","(" <> H.text op <> ")","only","works","with"
1549− ,H.dullyellow "Int","and",H.dullyellow "Float","values."
1547+ [ D.fillSep
1548+ ["But","(" <> D.fromString op <> ")","only","works","with"
1549+ ,D.dullyellow "Int","and",D.dullyellow "Float","values."
15501550 ]
15511551 ]
15521552 ++ otherHints
@@ -1554,33 +1554,33 @@ badMath localizer category operation direction op tipe expected otherHints =
15541554 )
15551555
15561556
1557−badFDiv :: T.Localizer -> H.Doc -> T.Type -> T.Type -> (H.Doc, H.Doc)
1557+badFDiv :: T.Localizer -> D.Doc -> T.Type -> T.Type -> (D.Doc, D.Doc)
15581558badFDiv localizer direction tipe expected =
15591559 (
1560− H.reflow $
1560+ D.reflow $
15611561 "The (/) operator is specifically for floating-point division:"
15621562 ,
15631563 if isInt tipe then
1564− H.stack
1565− [ H.fillSep
1564+ D.stack
1565+ [ D.fillSep
15661566 ["The",direction,"side","of","(/)","must","be","a"
1567− ,H.dullyellow "Float" <> ","
1568− ,"but","I","am","seeing","an",H.dullyellow "Int" <> "."
1567+ ,D.dullyellow "Float" <> ","
1568+ ,"but","I","am","seeing","an",D.dullyellow "Int" <> "."
15691569 ,"I","recommend:"
15701570 ]
1571− , H.vcat
1572− [ H.green "toFloat" <> " for explicit conversions " <> H.black "(toFloat 5 / 2) == 2.5"
1573− , H.green "(//) " <> " for integer division " <> H.black "(5 // 2) == 2"
1571+ , D.vcat
1572+ [ D.green "toFloat" <> " for explicit conversions " <> D.black "(toFloat 5 / 2) == 2.5"
1573+ , D.green "(//) " <> " for integer division " <> D.black "(5 // 2) == 2"
15741574 ]
1575− , H.link "Note" "Read" "implicit-casts" "to learn why Elm does not implicitly convert Ints to Floats."
1575+ , D.link "Note" "Read" "implicit-casts" "to learn why Elm does not implicitly convert Ints to Floats."
15761576 ]
15771577
15781578 else
15791579 loneType localizer tipe expected
15801580 (
1581− H.fillSep
1581+ D.fillSep
15821582 ["The",direction,"side","of","(/)","must","be","a"
1583− ,H.dullyellow "Float" <> ","
1583+ ,D.dullyellow "Float" <> ","
15841584 ,"but","instead","I","am","seeing:"
15851585 ]
15861586 , []
@@ -1588,35 +1588,35 @@ badFDiv localizer direction tipe expected =
15881588 )
15891589
15901590
1591−badIDiv :: T.Localizer -> H.Doc -> T.Type -> T.Type -> (H.Doc, H.Doc)
1591+badIDiv :: T.Localizer -> D.Doc -> T.Type -> T.Type -> (D.Doc, D.Doc)
15921592badIDiv localizer direction tipe expected =
15931593 (
1594− H.reflow $
1594+ D.reflow $
15951595 "The (//) operator is specifically for integer division:"
15961596 ,
15971597 if isFloat tipe then
1598− H.stack
1599− [ H.fillSep
1598+ D.stack
1599+ [ D.fillSep
16001600 ["The",direction,"side","of","(//)","must","be","an"
1601− ,H.dullyellow "Int" <> ","
1602− ,"but","I","am","seeing","a",H.dullyellow "Float" <> "."
1601+ ,D.dullyellow "Int" <> ","
1602+ ,"but","I","am","seeing","a",D.dullyellow "Float" <> "."
16031603 ,"I","recommend","doing","the","conversion","explicitly"
16041604 ,"with","one","of","these","functions:"
16051605 ]
1606− , H.vcat
1607− [ H.green "round" <> " 3.5 == 4"
1608− , H.green "floor" <> " 3.5 == 3"
1609− , H.green "ceiling" <> " 3.5 == 4"
1610− , H.green "truncate" <> " 3.5 == 3"
1606+ , D.vcat
1607+ [ D.green "round" <> " 3.5 == 4"
1608+ , D.green "floor" <> " 3.5 == 3"
1609+ , D.green "ceiling" <> " 3.5 == 4"
1610+ , D.green "truncate" <> " 3.5 == 3"
16111611 ]
1612− , H.link "Note" "Read" "implicit-casts" "to learn why Elm does not implicitly convert Ints to Floats."
1612+ , D.link "Note" "Read" "implicit-casts" "to learn why Elm does not implicitly convert Ints to Floats."
16131613 ]
16141614 else
16151615 loneType localizer tipe expected
16161616 (
1617− H.fillSep
1617+ D.fillSep
16181618 ["The",direction,"side","of","(//)","must","be","an"
1619− ,H.dullyellow "Int" <> ","
1619+ ,D.dullyellow "Int" <> ","
16201620 ,"but","instead","I","am","seeing:"
16211621 ]
16221622 , []
@@ -1628,17 +1628,17 @@ badIDiv localizer direction tipe expected =
16281628-- BAD BOOLS
16291629
16301630
1631−badBool :: T.Localizer -> H.Doc -> H.Doc -> T.Type -> T.Type -> (H.Doc, H.Doc)
1631+badBool :: T.Localizer -> D.Doc -> D.Doc -> T.Type -> T.Type -> (D.Doc, D.Doc)
16321632badBool localizer op direction tipe expected =
16331633 (
1634− H.reflow $
1634+ D.reflow $
16351635 "I am struggling with this boolean operation:"
16361636 ,
16371637 loneType localizer tipe expected
16381638 (
1639− H.fillSep
1639+ D.fillSep
16401640 ["Both","sides","of","(" <> op <> ")","must","be"
1641− ,H.dullyellow "Bool","values,","but","the",direction,"side","is:"
1641+ ,D.dullyellow "Bool","values,","but","the",direction,"side","is:"
16421642 ]
16431643 ,
16441644 []
@@ -1650,24 +1650,24 @@ badBool localizer op direction tipe expected =
16501650-- BAD COMPARISON
16511651
16521652
1653−badCompLeft :: T.Localizer -> Category -> String -> String -> T.Type -> T.Type -> (H.Doc, H.Doc)
1653+badCompLeft :: T.Localizer -> Category -> String -> String -> T.Type -> T.Type -> (D.Doc, D.Doc)
16541654badCompLeft localizer category op direction tipe expected =
16551655 (
1656− H.reflow $
1656+ D.reflow $
16571657 "I cannot do a comparison with this value:"
16581658 ,
16591659 loneType localizer tipe expected
16601660 (
1661− H.reflow $ toDescription category $
1661+ D.reflow $ toDescription category $
16621662 "The " <> direction <> " side of (" <> op <> ") is"
16631663 ,
1664− [ H.fillSep
1665− ["But","(" <> H.text op <> ")","only","works","on"
1666− ,H.dullyellow "Int" <> ","
1667− ,H.dullyellow "Float" <> ","
1668− ,H.dullyellow "Char" <> ","
1664+ [ D.fillSep
1665+ ["But","(" <> D.fromString op <> ")","only","works","on"
1666+ ,D.dullyellow "Int" <> ","
1667+ ,D.dullyellow "Float" <> ","
1668+ ,D.dullyellow "Char" <> ","
16691669 ,"and"
1670− ,H.dullyellow "String"
1670+ ,D.dullyellow "String"
16711671 ,"values.","It","can","work","on","lists","and","tuples"
16721672 ,"of","comparable","values","as","well,","but","it","is"
16731673 ,"usually","better","to","find","a","different","path."
@@ -1681,7 +1681,7 @@ badCompRight :: T.Localizer -> String -> T.Type -> T.Type -> RightDocs
16811681badCompRight localizer op tipe expected =
16821682 EmphBoth
16831683 (
1684− H.reflow $
1684+ D.reflow $
16851685 "I need both sides of (" <> op <> ") to be the same type:"
16861686 ,
16871687 typeComparison localizer expected tipe
@@ -1690,7 +1690,7 @@ badCompRight localizer op tipe expected =
16901690 ,
16911691 "But the right side is:"
16921692 ,
1693− [ H.reflow $
1693+ [ D.reflow $
16941694 "I cannot compare different types though! Which side of (" <> op <> ") is the problem?"
16951695 ]
16961696 )
@@ -1705,7 +1705,7 @@ badEquality :: T.Localizer -> String -> T.Type -> T.Type -> RightDocs
17051705badEquality localizer op tipe expected =
17061706 EmphBoth
17071707 (
1708− H.reflow $
1708+ D.reflow $
17091709 "I need both sides of (" <> op <> ") to be the same type:"
17101710 ,
17111711 typeComparison localizer expected tipe
@@ -1715,12 +1715,12 @@ badEquality localizer op tipe expected =
17151715 "But the right side is:"
17161716 ,
17171717 if isFloat tipe || isFloat expected then
1718− [ H.toSimpleNote $
1718+ [ D.toSimpleNote $
17191719 "Equality on floats is not 100% reliable due to the design of IEEE 754. I\
17201720 \ recommend a check like (abs (x - y) < 0.0001) instead."
17211721 ]
17221722 else
1723− [ H.reflow $
1723+ [ D.reflow $
17241724 "Different types can never be equal though! Which side is messed up?"
17251725 ]
17261726 )
@@ -1736,15 +1736,15 @@ toInfiniteReport source localizer region name overallType =
17361736 Report.Report "INFINITE TYPE" region [] $
17371737 Report.toCodeSnippet source region Nothing
17381738 (
1739− H.reflow $
1739+ D.reflow $
17401740 "I am inferring a weird self-referential type for " <> N.toString name <> ":"
17411741 ,
1742− H.stack
1743− [ H.reflow $
1742+ D.stack
1743+ [ D.reflow $
17441744 "Here is my best effort at writing down the type. You will see ∞ for\
17451745 \ parts of the type that repeat something already printed out infinitely."
1746− , H.indent 4 (H.dullyellow (T.toDoc localizer RT.None overallType))
1747− , H.reflowLink
1746+ , D.indent 4 (D.dullyellow (T.toDoc localizer RT.None overallType))
1747+ , D.reflowLink
17481748 "Staring at the type is usually not so helpful, so I recommend reading the hints at"
17491749 "infinite-type"
17501750 "to get unstuck."
compiler/src/Reporting/Render/Code.hs+15−17
@@ -12,8 +12,9 @@ module Reporting.Render.Code
1212
1313import qualified Data.List as List
1414import qualified Data.Text as Text
15−import Text.PrettyPrint.ANSI.Leijen (Doc, (<>), hardline, dullred, empty, text)
1615
16+import Reporting.Doc (Doc, (<>))
17+import qualified Reporting.Doc as D
1718import qualified Reporting.Region as R
1819
1920
@@ -40,11 +41,6 @@ toSource source =
4041 f a
4142
4243
43−(<==>) :: Doc -> Doc -> Doc
44−(<==>) a b =
45− a <> hardline <> b
46−
47−
4844render :: Source -> R.Region -> Maybe R.Region -> Doc
4945render (Source sourceLines) region@(R.Region start end) maybeSubRegion =
5046 let
@@ -64,7 +60,7 @@ render (Source sourceLines) region@(R.Region start end) maybeSubRegion =
6460 in
6561 case makeUnderline width endLine smallerRegion of
6662 Nothing ->
67− drawLines True width smallerRegion relevantLines empty
63+ drawLines True width smallerRegion relevantLines D.empty
6864
6965 Just underline ->
7066 drawLines False width smallerRegion relevantLines underline
@@ -80,7 +76,7 @@ makeUnderline width realEndLine (R.Region (R.Position start c1) (R.Position end
8076 spaces = replicate (c1 + width + 1) ' '
8177 zigzag = replicate (max 1 (c2 - c1)) '^'
8278 in
83− Just (text spaces <> dullred (text zigzag))
79+ Just (D.fromString spaces <> D.dullred (D.fromString zigzag))
8480
8581
8682drawLines :: Bool -> Int -> R.Region -> [(Int, Text.Text)] -> Doc -> Doc
@@ -89,13 +85,14 @@ drawLines addZigZag width (R.Region start end) sourceLines finalLine =
8985 (R.Position startLine _) = start
9086 (R.Position endLine _) = end
9187 in
92− foldr (<==>) finalLine $
93− map (drawLine addZigZag width startLine endLine) sourceLines
88+ D.vcat $
89+ map (drawLine addZigZag width startLine endLine) sourceLines
90+ ++ [finalLine]
9491
9592
9693drawLine :: Bool -> Int -> Int -> Int -> (Int, Text.Text) -> Doc
9794drawLine addZigZag width startLine endLine (n, line) =
98− addLineNumber addZigZag width startLine endLine n (text (Text.unpack line))
95+ addLineNumber addZigZag width startLine endLine n (D.fromText line)
9996
10097
10198addLineNumber :: Bool -> Int -> Int -> Int -> Int -> Doc -> Doc
@@ -109,11 +106,11 @@ addLineNumber addZigZag width start end n line =
109106
110107 spacer =
111108 if addZigZag && start <= n && n <= end then
112− dullred ">"
109+ D.dullred ">"
113110 else
114111 " "
115112 in
116− text lineNumber <> spacer <> line
113+ D.fromString lineNumber <> spacer <> line
117114
118115
119116
@@ -142,10 +139,11 @@ renderPair source@(Source sourceLines) region1 region2 =
142139 (Just line) = List.lookup startRow1 sourceLines
143140 in
144141 OneLine $
145− text lineNumber <> "| " <> text (Text.unpack line)
146− <> hardline
147− <> text spaces1 <> dullred (text zigzag1)
148− <> text spaces2 <> dullred (text zigzag2)
142+ D.vcat
143+ [ D.fromString lineNumber <> "| " <> D.fromText line
144+ , D.fromString spaces1 <> D.dullred (D.fromString zigzag1) <>
145+ D.fromString spaces2 <> D.dullred (D.fromString zigzag2)
146+ ]
149147
150148 else
151149 TwoChunks
compiler/src/Reporting/Render/Type.hs+25−25
@@ -21,8 +21,8 @@ import qualified AST.Canonical as Can
2121import qualified AST.Module.Name as ModuleName
2222import qualified Elm.Name as N
2323import qualified Reporting.Annotation as A
24−import qualified Reporting.Helpers as H
25−import Reporting.Helpers ( Doc, (<+>), (<>) )
24+import qualified Reporting.Doc as D
25+import Reporting.Doc ( Doc, (<+>), (<>) )
2626
2727
2828
@@ -39,12 +39,12 @@ lambda :: Context -> Doc -> Doc -> [Doc] -> Doc
3939lambda context arg1 arg2 args =
4040 let
4141 lambdaDoc =
42− H.sep (arg1 : map ("->" <+>) (arg2:args))
42+ D.sep (arg1 : map ("->" <+>) (arg2:args))
4343 in
4444 case context of
4545 None -> lambdaDoc
46− Func -> H.cat [ "(", lambdaDoc, ")" ]
47− App -> H.cat [ "(", lambdaDoc, ")" ]
46+ Func -> D.cat [ "(", lambdaDoc, ")" ]
47+ App -> D.cat [ "(", lambdaDoc, ")" ]
4848
4949
5050apply :: Context -> Doc -> [Doc] -> Doc
@@ -56,10 +56,10 @@ apply context name args =
5656 _:_ ->
5757 let
5858 applyDoc =
59− H.hang 4 (H.sep (name : args))
59+ D.hang 4 (D.sep (name : args))
6060 in
6161 case context of
62− App -> H.cat [ "(", applyDoc, ")" ]
62+ App -> D.cat [ "(", applyDoc, ")" ]
6363 Func -> applyDoc
6464 None -> applyDoc
6565
@@ -70,7 +70,7 @@ tuple a b cs =
7070 entries =
7171 zipWith (<+>) ("(" : repeat ",") (a:b:cs)
7272 in
73− H.sep [ H.cat entries, ")" ]
73+ D.sep [ D.cat entries, ")" ]
7474
7575
7676record :: [(Doc, Doc)] -> Maybe Doc -> Doc
@@ -80,16 +80,16 @@ record entries maybeExt =
8080 "{}"
8181
8282 (fields, Nothing) ->
83− H.sep
84− [ H.cat (zipWith (<+>) ("{" : repeat ",") fields)
83+ D.sep
84+ [ D.cat (zipWith (<+>) ("{" : repeat ",") fields)
8585 , "}"
8686 ]
8787
8888 (fields, Just ext) ->
89− H.sep
90− [ H.hang 4 $ H.sep $
89+ D.sep
90+ [ D.hang 4 $ D.sep $
9191 [ "{" <+> ext
92− , H.cat (zipWith (<+>) ("|" : repeat ",") fields)
92+ , D.cat (zipWith (<+>) ("|" : repeat ",") fields)
9393 ]
9494 , "}"
9595 ]
@@ -97,7 +97,7 @@ record entries maybeExt =
9797
9898entryToDoc :: (Doc, Doc) -> Doc
9999entryToDoc (fieldName, fieldType) =
100− H.hang 4 (H.sep [ fieldName <+> ":", fieldType ])
100+ D.hang 4 (D.sep [ fieldName <+> ":", fieldType ])
101101
102102
103103recordSnippet :: (Doc, Doc) -> [(Doc, Doc)] -> Doc
@@ -106,7 +106,7 @@ recordSnippet entry entries =
106106 field = "{" <+> entryToDoc entry
107107 fields = zipWith (<+>) (repeat ",") (map entryToDoc entries ++ ["..."])
108108 in
109− H.sep [ H.cat (field:fields), "}" ]
109+ D.sep [ D.cat (field:fields), "}" ]
110110
111111
112112
@@ -126,22 +126,22 @@ srcToDoc context (A.At _ tipe) =
126126 (map (srcToDoc Func) rest)
127127
128128 Src.TVar name ->
129− H.nameToDoc name
129+ D.fromName name
130130
131131 Src.TType _ name args ->
132132 apply context
133− (H.nameToDoc name)
133+ (D.fromName name)
134134 (map (srcToDoc App) args)
135135
136136 Src.TTypeQual _ home name args ->
137137 apply context
138− (H.nameToDoc home <> "." <> H.nameToDoc name)
138+ (D.fromName home <> "." <> D.fromName name)
139139 (map (srcToDoc App) args)
140140
141141 Src.TRecord fields ext ->
142142 record
143143 (map fieldToDocs fields)
144− (fmap (H.nameToDoc . A.toValue) ext)
144+ (fmap (D.fromName . A.toValue) ext)
145145
146146 Src.TUnit ->
147147 "()"
@@ -155,7 +155,7 @@ srcToDoc context (A.At _ tipe) =
155155
156156fieldToDocs :: (A.Located N.Name, Src.Type) -> (Doc, Doc)
157157fieldToDocs (A.At _ fieldName, fieldType) =
158− ( H.nameToDoc fieldName
158+ ( D.fromName fieldName
159159 , srcToDoc None fieldType
160160 )
161161
@@ -190,17 +190,17 @@ canToDoc context tipe =
190190 (map (canToDoc Func) rest)
191191
192192 Can.TVar name ->
193− H.nameToDoc name
193+ D.fromName name
194194
195195 Can.TType (ModuleName.Canonical _ home) name args ->
196196 apply context
197− (H.nameToDoc home <> "." <> H.nameToDoc name)
197+ (D.fromName home <> "." <> D.fromName name)
198198 (map (canToDoc App) args)
199199
200200 Can.TRecord fields ext ->
201201 record
202202 (map entryToDocs (Map.toList fields))
203− (fmap H.nameToDoc ext)
203+ (fmap D.fromName ext)
204204
205205 Can.TUnit ->
206206 "()"
@@ -213,13 +213,13 @@ canToDoc context tipe =
213213
214214 Can.TAlias (ModuleName.Canonical _ home) name args _ ->
215215 apply context
216− (H.nameToDoc home <> "." <> H.nameToDoc name)
216+ (D.fromName home <> "." <> D.fromName name)
217217 (map (canToDoc App . snd) args)
218218
219219
220220entryToDocs :: (N.Name, Can.Type) -> (Doc, Doc)
221221entryToDocs (name, tipe) =
222− (H.nameToDoc name, canToDoc None tipe)
222+ (D.fromName name, canToDoc None tipe)
223223
224224
225225collectArgs :: Can.Type -> (Can.Type, [Can.Type])
compiler/src/Reporting/Warning.hs+10−10
@@ -13,11 +13,11 @@ import Data.Monoid ((<>))
1313import qualified AST.Canonical as Can
1414import qualified AST.Utils.Type as Type
1515import qualified Elm.Name as N
16+import qualified Reporting.Doc as D
1617import qualified Reporting.Region as R
1718import qualified Reporting.Report as Report
1819import qualified Reporting.Render.Code as Code
1920import qualified Reporting.Render.Type as RT
20−import qualified Reporting.Helpers as H
2121
2222
2323
@@ -44,7 +44,7 @@ toReport source warning =
4444 Report.Report "unused import" region [] $
4545 Report.toCodeSnippet source region Nothing
4646 (
47− H.reflow $
47+ D.reflow $
4848 "Nothing from the `" <> N.toString moduleName <> "` module is used in this file."
4949 ,
5050 "I recommend removing unused imports."
@@ -55,14 +55,14 @@ toReport source warning =
5555 Report.Report title region [] $
5656 Report.toCodeSnippet source region Nothing
5757 (
58− H.reflow $
58+ D.reflow $
5959 "You are not using `" <> N.toString name <> "` anywhere."
6060 ,
61− H.stack
62− [ H.reflow $
61+ D.stack
62+ [ D.reflow $
6363 "Is there a typo? Maybe you intended to use `" <> N.toString name
6464 <> "` somewhere but typed another name instead?"
65− , H.reflow $
65+ , D.reflow $
6666 defOrPat context
6767 ( "If you are sure there is no typo, remove the definition.\
6868 \ This way future readers will not have to wonder why it is there!"
@@ -77,7 +77,7 @@ toReport source warning =
7777 Report.Report "missing type annotation" region [] $
7878 Report.toCodeSnippet source region Nothing
7979 (
80− H.reflow $
80+ D.reflow $
8181 case Type.deepDealias inferredType of
8282 Can.TLambda _ _ ->
8383 "The `" <> N.toString name <> "` function has no type annotation."
@@ -85,10 +85,10 @@ toReport source warning =
8585 _ ->
8686 "The `" <> N.toString name <> "` definition has no type annotation."
8787 ,
88− H.stack
88+ D.stack
8989 [ "I inferred the type annotation myself though! You can copy it into your code:"
90− , H.green $ H.hang 4 $ H.sep $
91− [ H.nameToDoc name <> " :"
90+ , D.green $ D.hang 4 $ D.sep $
91+ [ D.fromName name <> " :"
9292 , RT.canToDoc RT.None inferredType
9393 ]
9494 ]
compiler/src/Type/Error.hs+45−45
@@ -25,7 +25,7 @@ import Data.Monoid ((<>))
2525import qualified AST.Module.Name as ModuleName
2626import qualified Data.Bag as Bag
2727import qualified Elm.Name as N
28−import qualified Reporting.Helpers as H
28+import qualified Reporting.Doc as D
2929import qualified Reporting.Render.Type as RT
3030
3131
@@ -78,17 +78,17 @@ iteratedDealias tipe =
7878type Localizer = Map.Map (ModuleName.Canonical, N.Name) String
7979
8080
81−nameToDoc :: Localizer -> ModuleName.Canonical -> N.Name -> H.Doc
81+nameToDoc :: Localizer -> ModuleName.Canonical -> N.Name -> D.Doc
8282nameToDoc dict home@(ModuleName.Canonical _ moduleName) name =
8383 case Map.lookup (home, name) dict of
8484 Nothing ->
85− H.nameToDoc moduleName <> "." <> H.nameToDoc name
85+ D.fromName moduleName <> "." <> D.fromName name
8686
8787 Just string ->
88− H.text string
88+ D.fromString string
8989
9090
91−toDoc :: Localizer -> RT.Context -> Type -> H.Doc
91+toDoc :: Localizer -> RT.Context -> Type -> D.Doc
9292toDoc dict ctx tipe =
9393 case tipe of
9494 Lambda a b cs ->
@@ -104,16 +104,16 @@ toDoc dict ctx tipe =
104104 "?"
105105
106106 FlexVar name ->
107− H.nameToDoc name
107+ D.fromName name
108108
109109 FlexSuper _ name ->
110− H.nameToDoc name
110+ D.fromName name
111111
112112 RigidVar name ->
113− H.nameToDoc name
113+ D.fromName name
114114
115115 RigidSuper _ name ->
116− H.nameToDoc name
116+ D.fromName name
117117
118118 Type home name args ->
119119 RT.apply ctx
@@ -123,7 +123,7 @@ toDoc dict ctx tipe =
123123 Record fields ext ->
124124 let
125125 entryToDocs (fieldName, fieldType) =
126− ( H.nameToDoc fieldName, toDoc dict RT.None fieldType )
126+ ( D.fromName fieldName, toDoc dict RT.None fieldType )
127127
128128 fieldDocs =
129129 map entryToDocs (Map.toList fields)
@@ -131,8 +131,8 @@ toDoc dict ctx tipe =
131131 RT.record fieldDocs $
132132 case ext of
133133 Closed -> Nothing
134− FlexOpen x -> Just (H.nameToDoc x)
135− RigidOpen x -> Just (H.nameToDoc x)
134+ FlexOpen x -> Just (D.fromName x)
135+ RigidOpen x -> Just (D.fromName x)
136136
137137 Unit ->
138138 "()"
@@ -153,7 +153,7 @@ toDoc dict ctx tipe =
153153-- DIFF
154154
155155
156−toDiffDocs :: Localizer -> Type -> Type -> (H.Doc, H.Doc, [Problem])
156+toDiffDocs :: Localizer -> Type -> Type -> (D.Doc, D.Doc, [Problem])
157157toDiffDocs dict a b =
158158 case diff dict RT.None a b of
159159 Similar aDoc bDoc ->
@@ -217,13 +217,13 @@ data Problem
217217-- COMPUTE DIFF
218218
219219
220−diff :: Localizer -> RT.Context -> Type -> Type -> Diff H.Doc
220+diff :: Localizer -> RT.Context -> Type -> Type -> Diff D.Doc
221221diff dict ctx tipe1 tipe2 =
222222 case (tipe1, tipe2) of
223− (FlexVar x, FlexVar y) | x == y -> pure (H.nameToDoc x)
224− (FlexSuper _ x, FlexSuper _ y) | x == y -> pure (H.nameToDoc x)
225− (RigidVar x, RigidVar y) | x == y -> pure (H.nameToDoc x)
226− (RigidSuper _ x, RigidSuper _ y) | x == y -> pure (H.nameToDoc x)
223+ (FlexVar x, FlexVar y) | x == y -> pure (D.fromName x)
224+ (FlexSuper _ x, FlexSuper _ y) | x == y -> pure (D.fromName x)
225+ (RigidVar x, RigidVar y) | x == y -> pure (D.fromName x)
226+ (RigidSuper _ x, RigidSuper _ y) | x == y -> pure (D.fromName x)
227227
228228 (Infinite, Infinite) -> pure "∞"
229229 (Error, Error) -> pure "?"
@@ -236,8 +236,8 @@ diff dict ctx tipe1 tipe2 =
236236 <*>
237237 case (maybeC, maybeZ) of
238238 (Nothing, Nothing) -> pure []
239− (Just c , Nothing) -> Different [H.dullyellow (toDoc dict RT.None c)] [] Bag.empty
240− (Nothing, Just z ) -> Different [] [H.dullyellow (toDoc dict RT.None z)] Bag.empty
239+ (Just c , Nothing) -> Different [D.dullyellow (toDoc dict RT.None c)] [] Bag.empty
240+ (Nothing, Just z ) -> Different [] [D.dullyellow (toDoc dict RT.None z)] Bag.empty
241241 (Just c , Just z ) -> (:[]) <$> diff dict RT.None c z
242242
243243 (Record fields1 ext1, Record fields2 ext2) -> diffRecord dict fields1 ext1 fields2 ext2
@@ -255,8 +255,8 @@ diff dict ctx tipe1 tipe2 =
255255
256256 (Lambda a b cs, Lambda x y zs) -> diffLambda dict ctx (a:b:cs) (x:y:zs)
257257
258− (FlexVar x, other) -> Similar (H.nameToDoc x) (toDoc dict ctx other)
259− (other, FlexVar x) -> Similar (toDoc dict ctx other) (H.nameToDoc x)
258+ (FlexVar x, other) -> Similar (D.fromName x) (toDoc dict ctx other)
259+ (other, FlexVar x) -> Similar (toDoc dict ctx other) (D.fromName x)
260260
261261 pair ->
262262 case pair of
@@ -268,8 +268,8 @@ diff dict ctx tipe1 tipe2 =
268268
269269 _ ->
270270 let
271− doc1 = H.dullyellow (toDoc dict ctx tipe1)
272− doc2 = H.dullyellow (toDoc dict ctx tipe2)
271+ doc1 = D.dullyellow (toDoc dict ctx tipe1)
272+ doc2 = D.dullyellow (toDoc dict ctx tipe2)
273273 in
274274 Different doc1 doc2 $
275275 case pair of
@@ -334,10 +334,10 @@ isSimilar tipe1 tipe2 =
334334 Different _ _ _ -> False
335335
336336
337−yellowApply :: Localizer -> RT.Context -> ModuleName.Canonical -> N.Name -> Type -> H.Doc
337+yellowApply :: Localizer -> RT.Context -> ModuleName.Canonical -> N.Name -> Type -> D.Doc
338338yellowApply dict ctx home name tipe =
339339 RT.apply ctx
340− (H.dullyellow (nameToDoc dict home name))
340+ (D.dullyellow (nameToDoc dict home name))
341341 [toDoc dict RT.App tipe]
342342
343343
@@ -348,7 +348,7 @@ yellowApply dict ctx home name tipe =
348348--
349349-- INVARIANT: length types1 >= 2 && length types2 >= 2
350350--
351−diffLambda :: Localizer -> RT.Context -> [Type] -> [Type] -> Diff H.Doc
351+diffLambda :: Localizer -> RT.Context -> [Type] -> [Type] -> Diff D.Doc
352352diffLambda dict ctx types1 types2 =
353353 let
354354 (result1:revArgs1) = reverse types1
@@ -389,7 +389,7 @@ diffLambda dict ctx types1 types2 =
389389--
390390-- INVARIANT: length shortRevArgs >= 2 && length longRevArgs >= 2
391391--
392−diffArgMismatch :: Localizer -> RT.Context -> [Type] -> H.Doc -> [Type] -> H.Doc -> Diff H.Doc
392+diffArgMismatch :: Localizer -> RT.Context -> [Type] -> D.Doc -> [Type] -> D.Doc -> Diff D.Doc
393393diffArgMismatch dict ctx shortRevArgs shortResult longRevArgs longResult =
394394 case toGreedyMatch dict shortRevArgs longRevArgs of
395395 Just (GreedyMatch shortRevArgDocs longRevArgDocs) ->
@@ -417,7 +417,7 @@ diffArgMismatch dict ctx shortRevArgs shortResult longRevArgs longResult =
417417 Nothing ->
418418 let
419419 toYellowDoc tipe =
420− H.dullyellow (toDoc dict RT.Func tipe)
420+ D.dullyellow (toDoc dict RT.Func tipe)
421421
422422 (a:b:cs) = reverse (shortResult : map toYellowDoc shortRevArgs)
423423 (x:y:zs) = reverse (longResult : map toYellowDoc longRevArgs )
@@ -433,7 +433,7 @@ diffArgMismatch dict ctx shortRevArgs shortResult longRevArgs longResult =
433433
434434
435435data GreedyMatch =
436− GreedyMatch [H.Doc] [H.Doc]
436+ GreedyMatch [D.Doc] [D.Doc]
437437
438438
439439--
@@ -448,7 +448,7 @@ toGreedyMatchHelp :: Localizer -> [Type] -> [Type] -> GreedyMatch -> Maybe Greed
448448toGreedyMatchHelp dict shorterArgs longerArgs match@(GreedyMatch shorterDocs longerDocs) =
449449 let
450450 toYellowDoc tipe =
451− H.dullyellow (toDoc dict RT.Func tipe)
451+ D.dullyellow (toDoc dict RT.Func tipe)
452452 in
453453 case (shorterArgs, longerArgs) of
454454 (x:xs, y:ys) ->
@@ -475,7 +475,7 @@ toGreedyMatchHelp dict shorterArgs longerArgs match@(GreedyMatch shorterDocs lon
475475-- RECORD DIFFS
476476
477477
478−diffRecord :: Localizer -> Map.Map N.Name Type -> Extension -> Map.Map N.Name Type -> Extension -> Diff H.Doc
478+diffRecord :: Localizer -> Map.Map N.Name Type -> Extension -> Map.Map N.Name Type -> Extension -> Diff D.Doc
479479diffRecord dict fields1 ext1 fields2 ext2 =
480480 let
481481 only1 = Map.keys (Map.difference fields1 fields2)
@@ -510,12 +510,12 @@ diffRecord dict fields1 ext1 fields2 ext2 =
510510 (Bag.one (FieldMismatch only1 only2))
511511
512512
513−toOverlapDoc :: (BadOverlap -> H.Doc) -> BadOverlap -> (H.Doc, H.Doc)
513+toOverlapDoc :: (BadOverlap -> D.Doc) -> BadOverlap -> (D.Doc, D.Doc)
514514toOverlapDoc getDoc overlap@(BadOverlap field _ _ _) =
515− (H.nameToDoc field, getDoc overlap)
515+ (D.fromName field, getDoc overlap)
516516
517517
518−toOverlapRecord :: (BadOverlap -> H.Doc) -> BadOverlap -> [BadOverlap] -> Extension -> H.Doc
518+toOverlapRecord :: (BadOverlap -> D.Doc) -> BadOverlap -> [BadOverlap] -> Extension -> D.Doc
519519toOverlapRecord getDoc bad bads ext =
520520 let go = toOverlapDoc getDoc in
521521 case ext of
@@ -524,7 +524,7 @@ toOverlapRecord getDoc bad bads ext =
524524 RigidOpen _ -> RT.recordSnippet (go bad) (map go bads)
525525
526526
527−toMissingDoc :: Map.Map N.Name t -> [N.Name] -> Extension -> H.Doc
527+toMissingDoc :: Map.Map N.Name t -> [N.Name] -> Extension -> D.Doc
528528toMissingDoc allFields uniqueFields ext =
529529 case map emphasizeFieldName uniqueFields of
530530 [] ->
@@ -540,12 +540,12 @@ toMissingDoc allFields uniqueFields ext =
540540 RigidOpen _ -> RT.recordSnippet doc docs
541541
542542
543−emphasizeFieldName :: N.Name -> (H.Doc, H.Doc)
543+emphasizeFieldName :: N.Name -> (D.Doc, D.Doc)
544544emphasizeFieldName field =
545− ( H.dullyellow (H.nameToDoc field), "..." )
545+ ( D.dullyellow (D.fromName field), "..." )
546546
547547
548−toBoringRecord :: Map.Map N.Name t -> Extension -> H.Doc
548+toBoringRecord :: Map.Map N.Name t -> Extension -> D.Doc
549549toBoringRecord fields ext =
550550 case ext of
551551 Closed -> if Map.null fields then "{}" else "{ ... }"
@@ -557,11 +557,11 @@ toBoringRecord fields ext =
557557-- DIFF RECORD EXTENSION
558558
559559
560−diffExt :: Extension -> Extension -> Diff (Maybe H.Doc)
560+diffExt :: Extension -> Extension -> Diff (Maybe D.Doc)
561561diffExt ext1 ext2 =
562562 let
563− normal = Just . H.nameToDoc
564− yellow = Just . H.dullyellow . H.nameToDoc
563+ normal = Just . D.fromName
564+ yellow = Just . D.dullyellow . D.fromName
565565
566566 different x y = Different x y Bag.empty
567567 in
@@ -596,8 +596,8 @@ diffExt ext1 ext2 =
596596data BadOverlap =
597597 BadOverlap
598598 { _field :: N.Name
599− , _doc1 :: H.Doc
600− , _doc2 :: H.Doc
599+ , _doc1 :: D.Doc
600+ , _doc2 :: D.Doc
601601 , _problems :: Bag.Bag Problem
602602 }
603603
@@ -608,7 +608,7 @@ findBadOverlaps dict fields1 fields2 =
608608 Map.intersectionWith (diff dict RT.None) fields1 fields2
609609
610610
611−findBadOverlapsHelp :: [BadOverlap] -> [(N.Name, Diff H.Doc)] -> [BadOverlap]
611+findBadOverlapsHelp :: [BadOverlap] -> [(N.Name, Diff D.Doc)] -> [BadOverlap]
612612findBadOverlapsHelp badOverlaps fieldPairs =
613613 case fieldPairs of
614614 [] ->
elm.cabal+4−4
@@ -134,7 +134,6 @@ Executable elm
134134 Elm.Header,
135135 Elm.Name,
136136 Elm.Package,
137− Elm.Utils,
138137 Json.Decode,
139138 Json.Encode,
140139
@@ -196,6 +195,7 @@ Executable elm
196195 Parse.Shader,
197196 Parse.Type,
198197 Reporting.Annotation,
198+ Reporting.Doc,
199199 Reporting.Error,
200200 Reporting.Error.Canonicalize,
201201 Reporting.Error.Docs,
@@ -203,12 +203,12 @@ Executable elm
203203 Reporting.Error.Pattern,
204204 Reporting.Error.Syntax,
205205 Reporting.Error.Type,
206− Reporting.Helpers,
207206 Reporting.Region,
208207 Reporting.Render.Code,
209208 Reporting.Render.Type,
210209 Reporting.Report,
211210 Reporting.Result,
211+ Reporting.Suggest,
212212 Reporting.Warning,
213213 Type.Constrain.Expression,
214214 Type.Constrain.Module,
@@ -224,8 +224,8 @@ Executable elm
224224 Paths_elm
225225
226226 Build-depends:
227− ansi-terminal >= 0.7 && < 0.8,
228− ansi-wl-pprint >= 0.6.7 && < 0.7,
227+ ansi-terminal >= 0.8 && < 0.9,
228+ ansi-wl-pprint >= 0.6.8 && < 0.7,
229229 base >=4.8 && <5,
230230 binary >= 0.8 && < 0.9,
231231 bytestring >= 0.9 && < 0.11,
ui/terminal/src/Repl.hs+1−1
@@ -29,7 +29,7 @@ import qualified Elm.Name as N
2929import qualified Elm.Project as Project
3030import qualified Elm.Package as Pkg
3131import qualified Elm.PerUserCache as PerUserCache
32−import qualified Elm.Utils as Elm
32+import qualified Parse.Repl as Elm
3333import qualified Reporting.Task as Task
3434import qualified Reporting.Progress.Repl as Repl
3535
ui/terminal/src/Terminal/Args/Error.hs+8−4
@@ -23,7 +23,7 @@ import qualified System.FilePath as FP
2323import System.IO (hPutStrLn, stderr)
2424import qualified Text.PrettyPrint.ANSI.Leijen as P
2525
26−import Elm.Utils (nearbyNames, distance)
26+import Reporting.Suggest as Suggest
2727import Terminal.Args.Internal
2828
2929
@@ -235,7 +235,7 @@ exitWithUnknown :: String -> [String] -> IO a
235235exitWithUnknown unknown knowns =
236236 let
237237 suggestions =
238− case map toGreen (nearbyNames id unknown knowns) of
238+ case map toGreen (Suggest.nearbyNames id unknown knowns) of
239239 [] ->
240240 []
241241
@@ -434,7 +434,11 @@ getNearbyFlagsHelp :: String -> Flag a -> (Int, String)
434434getNearbyFlagsHelp unknown flag =
435435 case flag of
436436 OnOff flagName _ ->
437− ( distance unknown flagName, "--" ++ flagName )
437+ ( Suggest.distance unknown flagName
438+ , "--" ++ flagName
439+ )
438440
439441 Flag flagName (Parser singular _ _ _ _) _ ->
440− ( distance unknown flagName, "--" ++ flagName ++ "=" ++ toToken singular )
442+ ( Suggest.distance unknown flagName
443+ , "--" ++ flagName ++ "=" ++ toToken singular
444+ )