@@ -1,4 +1,4 @@
1−module Elm.Compiler.Type.Extract where
1+module Elm.Compiler.Type.Extract (toFullType, toAliasedType) where
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
9−-- INTERNAL TYPE to PUBLIC TYPE
9+toFullType :: Type.Canonical -> T.Type
11−fromInternalType :: Type.Canonical -> T.Type
14+toAliasedType :: Type.Canonical -> T.Type
12−fromInternalType astType =
15+toAliasedType astType =
19+toType :: Bool -> Type.Canonical -> T.Type
20+toType useAliases astType =
22+ go = toType useAliases
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)
17 Type.Var x ->
28 Type.Var x ->
@@ -21,10 +32,13 @@ fromInternalType astType =
21 T.Type (Var.toString var)
32 T.Type (Var.toString var)
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)
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)
29− Type.Aliased _name args t ->
40+ Type.Aliased name args t ->
42+ T.App (T.Type (Var.toString name)) (map (go . snd) args)
30− fromInternalType (Type.dealias args t)
44+ go (Type.dealias args t)