[Haskell-cafe] Getting list of constructors of a Type

Alejandro Serrano Mena trupill at gmail.com
Wed Jun 4 12:30:38 UTC 2014


My aim is to extend the capabilities of ghc-mod to do case split. For that
matter, I'm using the GHC module of the ghc package (the same ghc-mod
uses). Via the exprType function I get a Type value. Then, I would like to
be able to call getInfo (everything from the GHC module) to get the
information of that type.

I'm not sure if using Template Haskell is something I can use, but I will
definitely try :)


2014-06-04 0:01 GMT+02:00 Nils Schweinsberg <mail at nils.cc>:

> I'm not sure what exactly you're trying to do, but with Template Haskell
> it's easy:
>
>  test :: Name -> Q [Dec]
>> test name = do
>>   info <- reify name
>>   ...
>>
>
> Then call it from another module with the type name as argument (double
> single quotes):
>
>  data Test = A | B
>>
>> test ''Test
>>
>
> The `Info` type returned by `reify` is described in:
>
> http://hackage.haskell.org/package/template-haskell-2.9.
> 0.0/docs/Language-Haskell-TH-Syntax.html#t:Info
>
>
> - Nils
>
> Am 03.06.2014 21:13, schrieb Alejandro Serrano Mena:
>
>> Dear Haskell-Café,
>> As part of my Google Summer of Code, I need to get the list of data
>> constructors of a certain data type on a specific scenario.
>> In my case, I'm getting a value of type Type (by calling exprType). I
>> was expecting to be able to call getInfo directly on that value of type
>> Type, but it doesn't have a name nor the constructors of Type are
>> public. Thus, I'm not able to get that information :(
>>
>> Thanks in advance,
>> Alejandro
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140604/fb5c8c40/attachment.html>


More information about the Haskell-Cafe mailing list