module Fay.Compiler.GADT
(convertGADT
) where
import Language.Haskell.Exts hiding (name)
convertGADT :: GadtDecl a -> QualConDecl a
convertGADT :: GadtDecl a -> QualConDecl a
convertGADT GadtDecl a
d = case GadtDecl a
d of
GadtDecl a
s Name a
name Maybe [TyVarBind a]
tyvars Maybe (Context a)
context Maybe [FieldDecl a]
Nothing Type a
typ ->
a
-> Maybe [TyVarBind a]
-> Maybe (Context a)
-> ConDecl a
-> QualConDecl a
forall l.
l
-> Maybe [TyVarBind l]
-> Maybe (Context l)
-> ConDecl l
-> QualConDecl l
QualConDecl a
s Maybe [TyVarBind a]
tyvars Maybe (Context a)
context (a -> Name a -> [Type a] -> ConDecl a
forall l. l -> Name l -> [Type l] -> ConDecl l
ConDecl a
s Name a
name (Type a -> [Type a]
forall a. Type a -> [Type a]
convertFunc Type a
typ))
GadtDecl a
s Name a
name Maybe [TyVarBind a]
tyvars Maybe (Context a)
context (Just [FieldDecl a]
fs) Type a
_typ ->
a
-> Maybe [TyVarBind a]
-> Maybe (Context a)
-> ConDecl a
-> QualConDecl a
forall l.
l
-> Maybe [TyVarBind l]
-> Maybe (Context l)
-> ConDecl l
-> QualConDecl l
QualConDecl a
s Maybe [TyVarBind a]
tyvars Maybe (Context a)
context (a -> Name a -> [FieldDecl a] -> ConDecl a
forall l. l -> Name l -> [FieldDecl l] -> ConDecl l
RecDecl a
s Name a
name [FieldDecl a]
fs)
where
convertFunc :: Type a -> [Type a]
convertFunc :: Type a -> [Type a]
convertFunc (TyCon a
_ QName a
_) = []
convertFunc (TyFun a
_ Type a
x Type a
xs) = Type a
x Type a -> [Type a] -> [Type a]
forall a. a -> [a] -> [a]
: Type a -> [Type a]
forall a. Type a -> [Type a]
convertFunc Type a
xs
convertFunc (TyParen a
_ Type a
x) = Type a -> [Type a]
forall a. Type a -> [Type a]
convertFunc Type a
x
convertFunc Type a
_ = []