[Haskell-cafe] Lenses and records and ecosystem

David Menendez dave at zednenem.com
Sat Feb 11 21:04:03 UTC 2017


On Fri, Feb 10, 2017 at 7:53 PM, Anthony Clayden <
anthony_clayden at clear.net.nz> wrote:

>
> Certainly (.) for lenses works 'backwards'
> (i.e. suffix style)
> compared to function-prefix style.
> (As any Lens tutorial will say.)
>

Those tutorials are oversimplifying. Lenses (and their relatives) transform
operations, not values. Composition of lenses is exactly like composition
of functions, with the inner-most operation on the right. A lens foo ::
Lens O I transforms an operation on I into an operation on O. A composition
outer.inner turns an operation on the target of inner into an operation on
the source of outer.

This is demonstrated by the way over distributes with (.):

    over (outer . inner) = over outer . over inner

What confuses people is view, which is contravariant:

    view (outer . inner) = view inner . view outer

but you can’t avoid having one of over and view be contravariant.

-- 
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170211/495cba07/attachment.html>


More information about the Haskell-Cafe mailing list