on master help sign in
When extracting types, use type aliases
commit0b499e6befeba12ef1543c2e79f40299bda813a6 authorEvan Czaplicki <info@elm-lang.org> dateWed 24 Jun 2015, 18:45 (11 years ago) parent1a835d8
4 files changed+31−17
src/Docs/Centralize.hs+3−3 src/Elm/Compiler/Module.hs+4−4 src/Elm/Compiler/Type.hs+1−1 src/Elm/Compiler/Type/Extract.hs+23−9
src/Docs/Centralize.hs+3−3
@@ -58,7 +58,7 @@ addDeclToDocs (A.A (region,maybeComment) decl) docs =
5858 let
5959 info =
6060 ( maybeComment
61− , fmap (Extract.fromInternalType . A.drop) maybeType
61+ , fmap (Extract.toAliasedType . A.drop) maybeType
6262 )
6363
6464 newValues =
@@ -72,7 +72,7 @@ addDeclToDocs (A.A (region,maybeComment) decl) docs =
7272 D.Datatype name args ctors ->
7373 let
7474 ctors' =
75− map (second (map Extract.fromInternalType)) ctors
75+ map (second (map Extract.toAliasedType)) ctors
7676
7777 union =
7878 A.A region (Docs.Union maybeComment args ctors')
@@ -82,7 +82,7 @@ addDeclToDocs (A.A (region,maybeComment) decl) docs =
8282 D.TypeAlias name args tipe ->
8383 let
8484 alias =
85− A.A region (Docs.Alias maybeComment args (Extract.fromInternalType tipe))
85+ A.A region (Docs.Alias maybeComment args (Extract.toAliasedType tipe))
8686 in
8787 docs { rawAliases = Map.insert name alias (rawAliases docs) }
8888
src/Elm/Compiler/Module.hs+4−4
@@ -5,7 +5,7 @@ module Elm.Compiler.Module
55 , hyphenate, dehyphenate
66 , defaultImports
77 , interfacePorts
8− , interfaceTypes
8+ , interfaceAliasedTypes
99 )
1010 where
1111
@@ -44,9 +44,9 @@ interfacePorts interface =
4444 Module.iPorts interface
4545
4646
47−interfaceTypes :: Interface -> Map.Map String Type.Type
48−interfaceTypes interface =
49− Map.map Extract.fromInternalType (Module.iTypes interface)
47+interfaceAliasedTypes :: Interface -> Map.Map String Type.Type
48+interfaceAliasedTypes interface =
49+ Map.map Extract.toAliasedType (Module.iTypes interface)
5050
5151
5252-- STRING CONVERSIONS for NAMES
src/Elm/Compiler/Type.hs+1−1
@@ -129,7 +129,7 @@ flattenRecord tipe =
129129
130130instance Json.ToJSON Type where
131131 toJSON tipe =
132− Json.String (Text.pack (toString tipe))
132+ Json.String (Text.unwords (Text.words (Text.pack (toString tipe))))
133133
134134
135135instance 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
22
33import Control.Arrow (second)
44import qualified AST.Type as Type
@@ -6,13 +6,24 @@ import qualified AST.Variable as Var
66import qualified Elm.Compiler.Type as T
77
88
9−-- INTERNAL TYPE to PUBLIC TYPE
9+toFullType :: Type.Canonical -> T.Type
10+toFullType astType =
11+ toType False astType
1012
11−fromInternalType :: Type.Canonical -> T.Type
12−fromInternalType astType =
13+
14+toAliasedType :: Type.Canonical -> T.Type
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
1324 case astType of
1425 Type.Lambda t1 t2 ->
15− T.Lambda (fromInternalType t1) (fromInternalType t2)
26+ T.Lambda (go t1) (go t2)
1627
1728 Type.Var x ->
1829 T.Var x
@@ -21,10 +32,13 @@ fromInternalType astType =
2132 T.Type (Var.toString var)
2233
2334 Type.App t ts ->
24− T.App (fromInternalType t) (map fromInternalType ts)
35+ T.App (go t) (map go ts)
2536
2637 Type.Record fields ext ->
27− T.Record (map (second fromInternalType) fields) (fmap fromInternalType ext)
38+ T.Record (map (second go) fields) (fmap go ext)
2839
29− Type.Aliased _name args t ->
30− fromInternalType (Type.dealias 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
44+ go (Type.dealias args t)