Say I have the following:
data Rec = Rec {
alpha :: Int,
beta :: Double,
phi :: Float
}
sample = Rec 1 2.3 4.5
I understand Template Haskell & the reify
function can get me the record's field names. That is:
print $(f sample) --> ["alpha", "beta", "phi"]
There is also a claim that this can be done without Template Haskell. Can someone provide an example implementation for this can be accomplished?
Typable
black magic? Either way, most uses one could put this information to would be a great fit for Template Haskell. – GeorgyData.Data
or you can just deriveShow
, showsample
and do a little parsing of that string. – Kenton