
Is there a way to tell, let's say, how many constructors there are for a type? Or do I need one of the haskell extensions I've read about?

On Thu, Oct 1, 2009 at 6:22 PM, Gregory Propf
Is there a way to tell, let's say, how many constructors there are for a type? Or do I need one of the haskell extensions I've read about?
Use Data.Data and derive Data for the types you are interested in or instance it for pre-existing types that aren't already instances. Introspection is tedious but trivial. http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Data.html

On Oct 1, 2009, at 19:22 , Gregory Propf wrote:
Is there a way to tell, let's say, how many constructors there are for a type? Or do I need one of the haskell extensions I've read about?
If the constructors are nullary (that is: data MyData = Foo | Bar | Baz) you could derive Enum and Bounded, then (maxBound :: MyData) is one less than the number of constructors. Anything more complicated requires deriving Data or Typeable (I've done it with the latter but don't recall details off the top of my head). -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

Thanks, I'll check out Data and Typeable
--- On Thu, 10/1/09, Brandon S. Allbery KF8NH
participants (3)
-
Brandon S. Allbery KF8NH
-
Derek Elkins
-
Gregory Propf