
Nicola,
Could you be looking for the OverloadedRecordFields[0] extension? This is
an extension that I *think* is slated to be in 7.10, and might do what you
want (though won't help you now).
If you declare two data types with the same field name (e.g. data A = A {
hello :: Int} and data B = B { hello :: Int }), the extension will generate
some typeclasses and type families so that you can use `hello` on both data
types.
(I haven't used this myself, but have been looking forward to it, so if
anyone wants to correct me on anything I've said please do so.)
[0] https://ghc.haskell.org/trac/ghc/wiki/Records/OverloadedRecordFields
On Sat, Oct 4, 2014 at 6:53 AM, Brandon Allbery
On Sat, Oct 4, 2014 at 5:57 AM, Nicola Gigante
wrote: However, it generates lenses, which at this time I don’t use in my little project. I'll learn to use them well sooner or later, I promise! In the meantime, is there some module out there than provides a template haskell function that do the same thing but generating simple accessor functions instead of lenses?
Anything that does this creates lenses. That does not mean that they all create Control.Lens, though; a lens is a general abstraction, not a trademark. The simplest version, focused solely on this use case, is probably the fclabels package.
Note that the reason they do what you need is that they are lenses. Simple accessors will conflict as you described. fclabels is still useful if you're only interested in lenses for record field accessors, though, since the full lens package is rather heavyweight in that case --- and as a bonus, you'll be getting a head start on the more general concept, without getting dropped into the deep end of the pool.
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe