[Haskell-cafe] Can you determine a constructor's arity using Data.Typeable and Data.Data?

David Fox ddssff at gmail.com
Thu Jun 25 12:54:12 EDT 2009


Oh, that make sense!

2009/6/25 José Pedro Magalhães <jpm at cs.uu.nl>

> Hey David,
>
> For instance:
>
> arity :: (Data a) => a -> Int
>> arity = length . gmapQ (const ())
>>
>
>
> Cheers,
> Pedro
>
> On Thu, Jun 25, 2009 at 17:31, David Fox <ddssff at gmail.com> wrote:
>
>> Is it possible to determine the arity of a value's constructor?
>> Suppose I have a value x of type
>>
>>   data A = B Int | C
>>
>> They typeOf function returns its TypeRep, which contains its type
>> constructor, but I don't see how to decide whether that
>> constructor's arity is 0 or 1.  If the type has field names
>> I can look at those using Data.Data.conFields and count them,
>> but if it doesn't I don't see how to do it.
>>
>> -david
>>
>>
>> _______________________________________________
>> 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/20090625/54c03ce3/attachment.html


More information about the Haskell-Cafe mailing list