Let us say we have
data D = X Int | Y Int Int | Z String
I wish to have a function getDConst
getDConst :: D -> String
that returns either "X", "Y", or "Z", according to the data constructor used for its input. Is there a generic way to write this without having to do case
on every data constructor? (I am ok with solutions relying on Data.Typeable
or something similar)
{-# LANGUAGE DeriveDataTypeable #-}
to the beginning of your file. It's necessary in GHC when you derive Data and Typeable. – Georgettegeorgi