[Haskell-cafe] What Haskell Records Need

Jonathan Geddes geddes.jonathan at gmail.com
Thu Aug 2 18:00:12 CEST 2012


Richard O'Keefe Said:
>> Ouch! And that's not even very deeply nested.
>> Imagine 4 or 5 levels deep. It really makes
>> Haskell feel clunky next to `a.b.c.d = val`
>> that you see in other languages.
>
>I was taught that this kind of thing violates the Law of Demeter
>and that an object should not be mutating the parts of an
>acquaintance's parts, but should ask the acquaintance to do so.
>I'd say that a.b.c.d = val is at the very least a sign that
>some encapsulation did not happen.

Absolutely! But in Haskell how do you do the
asking? I guess that's what I'm proposing is
a built in way of doing just that! I'm
shooting for as-easy-as the built in getters.

Erik Hesselink said:
>Isn't this exactly the problem solved by all the lens packages?

Yes it is. I think the existence of these
packages along with all the proposals to
change records is an indication that
something is missing from the language as a
whole. What I'm proposing is that the
language give you something that is
lightweight and easy to use to address this
issue. You can still use lenses on top of all
of this.

> makeLens myField myField'

If I remember correctly, one of the problems
with lenses is that they cannot support
polymorphic updates (updates which change a
type variable of the data). SEC functions, on
the other hand support polymorphic updates.

--Jonathan

On Thu, Aug 2, 2012 at 4:48 AM, Andrew Butterfield <
Andrew.Butterfield at scss.tcd.ie> wrote:

> Ah yes - the joy of Haskell
>
> It so easy to roll your own, rather than search to find someone else's
> (better/more elegant) solution...   :-)
>
>
> On 2 Aug 2012, at 11:41, Erik Hesselink wrote:
>
> > On Thu, Aug 2, 2012 at 12:30 PM, Andrew Butterfield
> > <Andrew.Butterfield at scss.tcd.ie> wrote:
> >>
> >> On 2 Aug 2012, at 09:25, Erik Hesselink wrote:
> >>
> >>> Isn't this exactly the problem solved by all the lens packages?
> >>> Current popular ones are fclabels [0] and data-lens [1].
> >>>
> >>> [0] http://hackage.haskell.org/package/fclabels
> >>> [1] http://hackage.haskell.org/package/data-lens
> >>
> >> Not sure what all of these do, but I have a simple solution I use
> >> in my work:
> >
> > They do exactly that. They create 'lenses' which are
> > getters/setters/modifiers combined, and allow you to compose these to
> > get/set/modify deep inside nested data types. Look at the examples in
> > the fclabels documentation [2] for more details.
> >
> > [2]
> http://hackage.haskell.org/packages/archive/fclabels/1.1.4/doc/html/Data-Label.html
>
> --------------------------------------------------------------------
> Andrew Butterfield     Tel: +353-1-896-2517     Fax: +353-1-677-2204
> Lero at TCD, Head of Foundations & Methods Research Group
> Director of Teaching and Learning - Undergraduate,
> School of Computer Science and Statistics,
> Room G.39, O'Reilly Institute, Trinity College, University of Dublin
>                           http://www.scss.tcd.ie/Andrew.Butterfield/
> --------------------------------------------------------------------
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120802/2b5be8fa/attachment.htm>


More information about the Haskell-Cafe mailing list