on 54dfb21 help sign in
elk/src/Elm/Compiler/Type/Extract.hs
44 lines 1.0 kB history raw
1module Elm.Compiler.Type.Extract (toFullType, toAliasedType) where
3import Control.Arrow (second)
4import qualified AST.Type as Type
5import qualified AST.Variable as Var
6import qualified Elm.Compiler.Type as T
9toFullType :: Type.Canonical -> T.Type
10toFullType astType =
11 toType False astType
14toAliasedType :: Type.Canonical -> T.Type
15toAliasedType astType =
16 toType True astType
19toType :: Bool -> Type.Canonical -> T.Type
20toType useAliases astType =
21 let
22 go = toType useAliases
23 in
24 case astType of
25 Type.Lambda t1 t2 ->
26 T.Lambda (go t1) (go t2)
28 Type.Var x ->
29 T.Var x
31 Type.Type var ->
32 T.Type (Var.toString var)
34 Type.App t ts ->
35 T.App (go t) (map go ts)
37 Type.Record fields ext ->
38 T.Record (map (second go) fields) (fmap go ext)
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)