by nilkn · 10y ago · 0 comments
For what it's worth, lenses can avoid some of these issues. For instance, they can allow you to have the same field name in multiple records:
data RecordA { _a_name :: String }
data RecordB { _b_name :: String }
makeLensesWith underscoreFields ''RecordA
makeLensesWith underscoreFields ''RecordB
You can now use something like `view name x` or `x^.name` for values of type `RecordA` or `RecordB`. Within the record definitions themselves, the field names still have to be disambiguated. The naming convention I chose here is pretty arbitrary. The first argument to `makeLensesWith` tells it how to parse the field names to get the "true" name.https://ghc.haskell.org/trac/ghc/wiki/Records/OverloadedReco... https://ghc.haskell.org/trac/ghc/wiki/Records/OverloadedReco...