on master help sign in
When extracting types, use type aliases
0b499e6Evan Czaplicki
src/Docs/Centralize.hs+3−3
@@ -58,7 +58,7 @@ addDeclToDocs (A.A (region,maybeComment) decl) docs =
58 let
58 let
59 info =
59 info =
60 ( maybeComment
60 ( maybeComment
61− , fmap (Extract.fromInternalType . A.drop) maybeType
61+ , fmap (Extract.toAliasedType . A.drop) maybeType
62 )
62 )
63
63
64 newValues =
64 newValues =
@@ -72,7 +72,7 @@ addDeclToDocs (A.A (region,maybeComment) decl) docs =
72 D.Datatype name args ctors ->
72 D.Datatype name args ctors ->
73 let
73 let
74 ctors' =
74 ctors' =
75− map (second (map Extract.fromInternalType)) ctors
75+ map (second (map Extract.toAliasedType)) ctors
76
76
77 union =
77 union =
78 A.A region (Docs.Union maybeComment args ctors')
78 A.A region (Docs.Union maybeComment args ctors')
@@ -82,7 +82,7 @@ addDeclToDocs (A.A (region,maybeComment) decl) docs =
82 D.TypeAlias name args tipe ->
82 D.TypeAlias name args tipe ->
83 let
83 let
84 alias =
84 alias =
85− A.A region (Docs.Alias maybeComment args (Extract.fromInternalType tipe))
85+ A.A region (Docs.Alias maybeComment args (Extract.toAliasedType tipe))
86 in
86 in
87 docs { rawAliases = Map.insert name alias (rawAliases docs) }
87 docs { rawAliases = Map.insert name alias (rawAliases docs) }
88
88
src/Elm/Compiler/Module.hs+4−4
@@ -5,7 +5,7 @@ module Elm.Compiler.Module
5 , hyphenate, dehyphenate
5 , hyphenate, dehyphenate
6 , defaultImports
6 , defaultImports
7 , interfacePorts
7 , interfacePorts
8− , interfaceTypes
8+ , interfaceAliasedTypes
9 )
9 )
10 where
10 where
11
11
@@ -44,9 +44,9 @@ interfacePorts interface =
44 Module.iPorts interface
44 Module.iPorts interface
45
45
46
46
47−interfaceTypes :: Interface -> Map.Map String Type.Type
47+interfaceAliasedTypes :: Interface -> Map.Map String Type.Type
48−interfaceTypes interface =
48+interfaceAliasedTypes interface =
49− Map.map Extract.fromInternalType (Module.iTypes interface)
49+ Map.map Extract.toAliasedType (Module.iTypes interface)
50
50
51
51
52-- STRING CONVERSIONS for NAMES
52-- STRING CONVERSIONS for NAMES
src/Elm/Compiler/Type.hs+1−1
@@ -129,7 +129,7 @@ flattenRecord tipe =
129
129
130instance Json.ToJSON Type where
130instance Json.ToJSON Type where
131 toJSON tipe =
131 toJSON tipe =
132− Json.String (Text.pack (toString tipe))
132+ Json.String (Text.unwords (Text.words (Text.pack (toString tipe))))
133
133
134
134
135instance Json.FromJSON Type where
135instance Json.FromJSON Type where
src/Elm/Compiler/Type/Extract.hs+23−9
@@ -1,4 +1,4 @@
1−module Elm.Compiler.Type.Extract where
1+module Elm.Compiler.Type.Extract (toFullType, toAliasedType) where
2
2
3import Control.Arrow (second)
3import Control.Arrow (second)
4import qualified AST.Type as Type
4import qualified AST.Type as Type
@@ -6,13 +6,24 @@ import qualified AST.Variable as Var
6import qualified Elm.Compiler.Type as T
6import qualified Elm.Compiler.Type as T
7
7
8
8
9−-- INTERNAL TYPE to PUBLIC TYPE
9+toFullType :: Type.Canonical -> T.Type
10+toFullType astType =
11+ toType False astType
10
12
13+
11−fromInternalType :: Type.Canonical -> T.Type
14+toAliasedType :: Type.Canonical -> T.Type
12−fromInternalType astType =
15+toAliasedType astType =
16+ toType True astType
17+
18+
19+toType :: Bool -> Type.Canonical -> T.Type
20+toType useAliases astType =
21+ let
22+ go = toType useAliases
23+ in
13 case astType of
24 case astType of
14 Type.Lambda t1 t2 ->
25 Type.Lambda t1 t2 ->
15− T.Lambda (fromInternalType t1) (fromInternalType t2)
26+ T.Lambda (go t1) (go t2)
16
27
17 Type.Var x ->
28 Type.Var x ->
18 T.Var x
29 T.Var x
@@ -21,10 +32,13 @@ fromInternalType astType =
21 T.Type (Var.toString var)
32 T.Type (Var.toString var)
22
33
23 Type.App t ts ->
34 Type.App t ts ->
24− T.App (fromInternalType t) (map fromInternalType ts)
35+ T.App (go t) (map go ts)
25
36
26 Type.Record fields ext ->
37 Type.Record fields ext ->
27− T.Record (map (second fromInternalType) fields) (fmap fromInternalType ext)
38+ T.Record (map (second go) fields) (fmap go ext)
28
39
29− Type.Aliased _name args t ->
40+ Type.Aliased name args t ->
41+ if useAliases then
42+ T.App (T.Type (Var.toString name)) (map (go . snd) args)
43+ else
30− fromInternalType (Type.dealias args t)
44+ go (Type.dealias args t)