Template Haskell Function for Record Accessor Inheritance -
i have 2 datatypes, a
, b
, have defined as:
data = { afoo :: int, abar :: string } data b = b { bfoo :: int, bbar :: string, bbaz :: float }
i need create heterogeneous list of a
s , b
s, define sum type, c
, as:
data c = ca | cb b
i define functions
cfoo :: c -> int cbar :: c -> string
this can achieved pattern matching...
cfoo (ca a) = afoo cfoo (cb b) = bfoo b cbar (ca a) = abar cbar (cb b) = bbar b
...but becomes tedious data types of many fields. wondering if there simple solution using template haskell, or if wouldn't worth effort. have intermediate knowledge of haskell, relatively new template haskell. appreciated.
Comments
Post a Comment