@@ -2,7 +2,7 @@
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Elm.Compiler.Type
3module Elm.Compiler.Type
5− , Context(..)
5+ , RT.Context(..)
7 , DebugMetadata(..)
7 , DebugMetadata(..)
8 , Alias(..)
8 , Alias(..)
@@ -23,7 +23,9 @@ import qualified Parse.Primitives as Parse
23import qualified Parse.Type as Type
23import qualified Parse.Type as Type
24import qualified Reporting.Annotation as A
24import qualified Reporting.Annotation as A
25import qualified Reporting.Doc as D
25import qualified Reporting.Doc as D
26−import Reporting.Doc ((<>), (<+>))
26+import qualified Reporting.Render.Type as RT
27+import qualified Reporting.Render.Type.Localizer as L
27import qualified Json.Decode as Decode
29import qualified Json.Decode as Decode
28import qualified Json.Encode as Encode
30import qualified Json.Encode as Encode
29import Json.Encode ((==>))
31import Json.Encode ((==>))
@@ -34,12 +36,12 @@ import Json.Encode ((==>))
37− = Lambda Type Type
39+ = Lambda Type Type
38− | Var N.Name
40+ | Var N.Name
39− | Type N.Name [Type]
41+ | Type N.Name [Type]
40− | Record [(N.Name, Type)] (Maybe N.Name)
42+ | Record [(N.Name, Type)] (Maybe N.Name)
42− | Tuple Type Type [Type]
44+ | Tuple Type Type [Type]
45data DebugMetadata =
47data DebugMetadata =
@@ -58,90 +60,53 @@ data Union = Union N.Name [N.Name] [(N.Name, [Type])]
61−data Context = None | InType | InFunction
64−toDoc :: Context -> Type -> D.Doc
63+toDoc :: L.Localizer -> RT.Context -> Type -> D.Doc
65−toDoc context tipe =
64+toDoc localizer context tipe =
66 case tipe of
65 case tipe of
67 Lambda _ _ ->
66 Lambda _ _ ->
69− map (toDoc InFunction) (collectLambdas tipe)
69+ map (toDoc localizer RT.Func) (collectLambdas tipe)
72− D.sep [ t, D.sep (map ("->" <+>) ts) ]
74− case context of
71+ RT.lambda context a b cs
76− _ -> "(" <> lambda <> ")"
78 Var name ->
73 Var name ->
79− D.fromName name
74+ D.fromName name
84 Tuple a b cs ->
79 Tuple a b cs ->
86− [ D.cat $
81+ (toDoc localizer RT.None a)
87− [ "(" <+> toDoc None a
82+ (toDoc localizer RT.None b)
88− , "," <+> toDoc None b
90− ++ map ("," <+>) (map (toDoc None) cs)
83+ (map (toDoc localizer RT.None) cs)
94 Type name args ->
85 Type name args ->
95− case args of
86+ RT.apply
102− D.fromName name
88+ (D.fromName name)
103−
89+ (map (toDoc localizer RT.App) args)
105− D.hang 2 $ D.sep (docName : map (toDoc InType) args)
109− "(" <> application <> ")"
114− Record [] Nothing ->
117 Record fields ext ->
91 Record fields ext ->
118− case ext of
92+ RT.record
121− [ D.cat (zipWith (<+>) ("{" : repeat ",") (map entryToDoc fields))
93+ (map (entryToDoc localizer) fields)
122− , "}"
94+ (fmap D.fromName ext)
127− [ D.hang 4 $ D.sep $
128− [ "{" <+> D.fromName x
129− , D.cat (zipWith (<+>) ("|" : repeat ",") (map entryToDoc fields))
135−entryToDoc :: (N.Name, Type) -> D.Doc
97+entryToDoc :: L.Localizer -> (N.Name, Type) -> (D.Doc, D.Doc)
136−entryToDoc (field, fieldType) =
98+entryToDoc localizer (field, fieldType) =
137− D.fromName field <+> ":" <+> toDoc None fieldType
99+ ( D.fromName field, toDoc localizer RT.None fieldType )
140collectLambdas :: Type -> [Type]
102collectLambdas :: Type -> [Type]
141collectLambdas tipe =
103collectLambdas tipe =
142 case tipe of
104 case tipe of
143− Lambda arg body -> arg : collectLambdas body
106+ arg : collectLambdas body
144− _ -> [tipe]
109+ [tipe]
@@ -150,7 +115,7 @@ collectLambdas tipe =
151encode :: Type -> Encode.Value
116encode :: Type -> Encode.Value
152encode tipe =
117encode tipe =
153− Encode.text $ Text.pack $ D.toLine (toDoc None tipe)
118+ Encode.text $ Text.pack $ D.toLine (toDoc L.empty RT.None tipe)
156decoder :: Decode.Decoder () Type
121decoder :: Decode.Decoder () Type