Given a data type
data Foo =
Foo1 { foo1Name :: String}
| Foo2 { foo2Name :: String, foo2Age :: Integer }
I would like to be able to extract the Data.Data.DataTypeS
of Foo1
and Foo2
s fields.
I tried
datatype = (undefined :: Foo)
constrs = dataTypeConstrs datatype
foo1 = fromConstrs (head constrs) :: Foo
foo1Fields = gmapQ dataTypeOf foo1
but foo1Fields
will just say that foo1Name
is a Prelude.[]
and not which type parameter is used.
Is it possible to extract type parameters using SYB or should I use another reflection library?