[Haskell-cafe] Automatically generate sum type members -> [String]
allbery.b at gmail.com
Mon May 18 23:27:51 UTC 2015
On Mon, May 18, 2015 at 7:20 PM, Cody Goodman <codygman.consulting at gmail.com
> Can I use either template Haskell, GHC Generics, or something else to
> get the list of Constructors in Codes? Then I could do `map show
> codeSumTypeMembers` and get `["A0100A","A0500A"]`?
Derive Enum and Bounded as well, and you can then use minBound and maxBound
along with show. This will only work for nullary constructors, though.
IIRC, with Data.Typeable (deriving (Typeable)) you can do something like
this for non-nullary constructors as well. It's more painful, though.
brandon s allbery kf8nh sine nomine associates
allbery.b at gmail.com ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe