[Haskell-cafe] How to get a list of constructors for a type?

2009-12-30 Thread Gregory Propf
Say I have something like data DT a = Foo a | Bar a | Boo a I want something like a list of the constructors of DT, perhaps as [TypeRep].  I'm using Data.Typeable but can't seem to find what I need in there.  Everything there operates over constructors, not types.

Re: [Haskell-cafe] How to get a list of constructors for a type?

2009-12-30 Thread Claude Heiland-Allen
Gregory Propf wrote: Say I have something like data DT a = Foo a | Bar a | Boo a I want something like a list of the constructors of DT, perhaps as [TypeRep]. I'm using Data.Typeable but can't seem to find what I need in there. Everything there operates over constructors, not types. The

Re: [Haskell-cafe] How to get a list of constructors for a type?

2009-12-30 Thread Lennart Augustsson
I've put some of Oleg's code on hackage, named polytypeable. import Data.PolyTypeable main = print [polyTypeOf Nothing, polyTypeOf Just] This prints [Maybe a1,a1 - Maybe a1] To get a list of the actual constructors you need to derive Data.Data.Data and use that. -- Lennart On Wed, Dec