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? Or can I
configure the parameters of makeFieldsWith
to generate simple functions instead of
lenses?
There are none that I am aware of. I certainly don't think Control.Lens supports this.
Another related question: if I use makeFields
in more than one module, and different records
have fields with the same name, the generated
typeclasses will have the same name but will
be different, because declared twice in different
modules, am I right?
I believe this is correct.
Is there a way to use a unique
typeclass in the whole project for every generated
field of the same name?
If the typeclass already exists in the module, then it won't be generated. So if you are working on module B, and you import module A which exports the class in question, then I believe module B will just use the class from module A instead of creating its own. There are various helper functions in
Control.Lens.TH, such as "makeClassyFor", which are meant to help with this. However, I don't think your use case is covered well by these helper functions. If you get in touch with the lens devs (file an issue in their github tracker, or chat with them on irc), I'm sure they can help you accomplish what you desire.
n.b. lenses aren't all that scary. It is quite simple to retrieve the "simple accessor" from a lens. Just use "view".
import Control.Lens.Getter (view)
-- given this typeclass operation
fooLens :: HasFoo a => Lens' a Foo
-- just use view on it to extract the getter portion of the lens
foo :: HasFoo a => a -> Foo
foo = view fooLens