[Haskell-cafe] Introspection on types.

Gregory Propf gregorypropf at yahoo.com
Fri Oct 2 02:07:39 EDT 2009


Thanks, I'll check out Data and Typeable

--- On Thu, 10/1/09, Brandon S. Allbery KF8NH <allbery at ece.cmu.edu> wrote:

From: Brandon S. Allbery KF8NH <allbery at ece.cmu.edu>
Subject: Re: [Haskell-cafe] Introspection on types.
To: "Gregory Propf" <gregorypropf at yahoo.com>
Cc: "Brandon S. Allbery KF8NH" <allbery at ece.cmu.edu>, "Haskell-Cafe" <haskell-cafe at haskell.org>
Date: Thursday, October 1, 2009, 6:14 PM

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 at kf8nh.comsystem administrator [openafs,heimdal,too many hats] allbery at ece.cmu.eduelectrical and computer engineering, carnegie mellon university    KF8NH
 



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091002/40a27d52/attachment.html


More information about the Haskell-Cafe mailing list