[Haskell-cafe] Automatically generate sum type members -> [String]
codygman.consulting at gmail.com
Mon May 18 23:20:46 UTC 2015
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"]`?
Here's an example of solving this problem manually:
data Codes = A0100A | A0500A deriving Show
codeExists "A0100A" = True
codeExists "A0500A" = True
codeExists _ = False
main = print $ codeExists xmlElementName
where xmlElementName = "A0500A"
-- λ> main
More information about the Haskell-Cafe