
On Fri, Feb 10, 2017 at 7:53 PM, Anthony Clayden < anthony_clayden@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