[Haskell-beginners] Getting a variables type as a string at runtime
gmorgan1984 at gmail.com
Sun Jan 12 15:45:17 UTC 2014
Data.Typeable with Data.Data worked. Thank you.
Using Typeable alone was only giving me the type of the whole type.
Data.Data had the toConstr function needed to give me the particular
For reference if anyone is interested in the solution:
data A = A | B | C deriving (Typeable, Data)
typeName :: A -> String
typeName = show . toConstr
I needed to add DeriveDataTypeable extension to my cabal file
On Sun, Jan 12, 2014 at 2:53 PM, Brandon Allbery <allbery.b at gmail.com>wrote:
> On Sun, Jan 12, 2014 at 9:47 AM, Gareth Morgan <gmorgan1984 at gmail.com>wrote:
>> Won't show include all the components? I wanted to include only the type
> Types only exist at compile time normally. But if you add a Typeable
> constraint (see Data.Typeable and the DeriveDataTypeable extension) you can
> get type names at runtime.
> brandon s allbery kf8nh sine nomine
> allbery.b at gmail.com
> ballbery at sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> Beginners mailing list
> Beginners at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners