[Haskell-cafe] template haskell library for OO-like selector syntax?

Matt parsonsmatt at gmail.com
Tue May 15 01:01:48 UTC 2018


You can use `makeFields` from the `lens` package to get something like:

someData ^. field1 . field2

along with modifiers:

someData & field1 . field2 %~ (* 2)

and setters:

someData & field1 . field2 .~ 42

where `field1` is polymorphic and can apply to many different data types

Matt Parsons

On Mon, May 14, 2018 at 6:41 PM, Dennis Raddle <dennis.raddle at gmail.com>
wrote:

> In my current application, I'm really missing the ability from OO to do
> things like
>
> someData.field1.field2 = "foo"
>
> What's do I mean?
>
> - field selectors are scoped so that names don't clash with each other or
> global names
>
> - this way of selecting data can be used both for reading it, and for
> updating specific fields of some data deep in a data hierarchy (In Haskell,
> if using immutable data, this would requiring doing a data update on every
> level).
>
> Any attempt to do this in Haskell, for me anyway, results in an explosion
> of names and a lot of boilerplate code and a resulting heavy syntax.
>
> Is there a way of obtaining OO-like concise syntax, perhaps with Template
> Haskell?
>
> Dennis
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180514/25765208/attachment.html>


More information about the Haskell-Cafe mailing list