[Haskell-cafe] Automatically generate sum type members -> [String]
David Kraeutmann
kane at kane.cx
Mon May 18 23:27:41 UTC 2015
readConstr [1] from Data.Data will do the trick. DataType for a type can
be retrieved with dataTypeOf.
----
1:
https://hackage.haskell.org/package/base-4.8.0.0/docs/Data-Data.html#v:readConstr
On 5/19/2015 1:20 AM, Cody Goodman wrote:
> 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
> -- True
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4271 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150519/607fe6e6/attachment.bin>
More information about the Haskell-Cafe
mailing list