<div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="font-family:arial,sans-serif;font-size:13px">is there<br></span><span style="font-family:arial,sans-serif;font-size:13px">some module out there than provides a<br></span><span style="font-family:arial,sans-serif;font-size:13px">template haskell function that do the<br></span><span style="font-family:arial,sans-serif;font-size:13px">same thing but generating simple accessor<br></span><span style="font-family:arial,sans-serif;font-size:13px">functions instead of lenses? Or can I<br></span><span style="font-family:arial,sans-serif;font-size:13px">configure the parameters of makeFieldsWith<br></span><span style="font-family:arial,sans-serif;font-size:13px">to generate simple functions instead of<br></span></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="font-family:arial,sans-serif;font-size:13px">lenses?</span></blockquote><div><br></div><div>There are none that I am aware of. I certainly don't think Control.Lens supports this.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="font-family:arial,sans-serif;font-size:13px">Another related question: if I use makeFields<br></span><span style="font-family:arial,sans-serif;font-size:13px">in more than one module, and different records<br></span><span style="font-family:arial,sans-serif;font-size:13px">have fields with the same name, the generated<br></span><span style="font-family:arial,sans-serif;font-size:13px">typeclasses will have the same name but will<br></span><span style="font-family:arial,sans-serif;font-size:13px">be different, because declared twice in different<br></span><span style="font-family:arial,sans-serif;font-size:13px">modules, am I right?</span></blockquote><div><br></div><div>I believe this is correct.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="font-size:13px;font-family:arial,sans-serif">Is there a way to use a unique<br></span><span style="font-size:13px;font-family:arial,sans-serif">typeclass in the whole project for every generated<br></span><span style="font-size:13px;font-family:arial,sans-serif">field of the same name?</span></blockquote><div><br></div><div>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 <a href="http://Control.Lens.TH">Control.Lens.TH</a>, 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.</div><div><br></div><div>n.b. lenses aren't all that scary. It is quite simple to retrieve the "simple accessor" from a lens. Just use "view".</div><div><br></div><div>import Control.Lens.Getter (view)</div><div><br></div><div>-- given this typeclass operation<br></div><div>fooLens :: HasFoo a => Lens' a Foo</div><div><br></div><div>-- just use view on it to extract the getter portion of the lens</div><div>foo :: HasFoo a => a -> Foo</div><div>foo = view fooLens</div><div><br></div></div><div class="gmail_extra"><br clear="all"><div>-- Dan Burton</div>
<br><div class="gmail_quote">On Sat, Oct 4, 2014 at 11:02 AM, Andrew Gibiansky <span dir="ltr"><<a href="mailto:andrew.gibiansky@gmail.com" target="_blank">andrew.gibiansky@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Nicola,<div><br></div><div>Could you be looking for the OverloadedRecordFields[0] extension? This is an extension that I <i>think</i> is slated to be in 7.10, and might do what you want (though won't help you now). </div><div><br></div><div>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.</div><div><br></div><div>(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.)</div><div><br></div><div>[0] <a href="https://ghc.haskell.org/trac/ghc/wiki/Records/OverloadedRecordFields" target="_blank">https://ghc.haskell.org/trac/ghc/wiki/Records/OverloadedRecordFields</a></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Sat, Oct 4, 2014 at 6:53 AM, Brandon Allbery <span dir="ltr"><<a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div class="gmail_extra"><span><div class="gmail_quote">On Sat, Oct 4, 2014 at 5:57 AM, Nicola Gigante <span dir="ltr"><<a href="mailto:nicola.gigante@gmail.com" target="_blank">nicola.gigante@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="overflow:hidden">However, it generates lenses, which<br>
at this time I don’t use in my little project.<br>
I'll learn to use them well sooner or later,<br>
I promise! In the meantime, is there<br>
some module out there than provides a<br>
template haskell function that do the<br>
same thing but generating simple accessor<br>
functions instead of lenses?</div></blockquote></div><br></span>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.</div><div class="gmail_extra"><br></div><div class="gmail_extra">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.<span><font color="#888888"><br><div><br></div>-- <br><div dir="ltr"><div>brandon s allbery kf8nh                               sine nomine associates</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a>                                  <a href="mailto:ballbery@sinenomine.net" target="_blank">ballbery@sinenomine.net</a></div><div>unix, openafs, kerberos, infrastructure, xmonad        <a href="http://sinenomine.net" target="_blank">http://sinenomine.net</a></div></div>
</font></span></div></div>
<br></div></div><span class="">_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></span></blockquote></div><br></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>