@@ -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)