[Haskell-cafe] Representation of lenses

David Feuer david.feuer at gmail.com
Tue Jan 27 20:08:21 UTC 2015


One significant reason is that the getter/setter pair doesn't support
efficient update operations in a nested structure. Updating the
hundredth element of a list would require getting it, applying a
function to it, and then setting it. With the fancy type and magic
tricks, you only need to dig down to the right place once.

On Tue, Jan 27, 2015 at 1:09 PM, David Turner
<dct25-561bs at mythic-beasts.com> wrote:
> Thanks, I'll give that a watch.
>
> On 27 Jan 2015 17:23, "Charles Durham" <ratzes at gmail.com> wrote:
>>
>> You need to sign up for it, but this is a phenomenal talk by simon peyton
>> jones describing the idea behind lenses the way he understood it.
>>
>>
>> https://skillsmatter.com/skillscasts/4251-lenses-compositional-data-access-and-manipulation
>>
>> On Tue, Jan 27, 2015 at 12:18 PM, David Turner
>> <dct25-561bs at mythic-beasts.com> wrote:
>>>
>>> Hi,
>>>
>>> I'm planning on discussing lenses with some colleagues shortly so I'm
>>> consolidating some of my notes into a coherent story. At one point I
>>> found myself describing lenses as a way of packaging up a getter and a
>>> setter into a single thing. However, this raises the question: why not
>>> just use a pair (getter, setter)? More precisely, I believe that the
>>> types (a -> s, s -> a -> a) and (forall f. Functor f => (s -> f s) ->
>>> a -> f a) are isomorphic. Is that right?
>>>
>>> I see that one advantage of the lens type is that you can use (.) to
>>> compose them since they're just functions, but that doesn't bother me
>>> much and it seems I could define another operator to compose (getter,
>>> setter) lenses and the rest of the machinery would work either way.
>>>
>>> It's also possible that you can't get the full generality of (forall
>>> f. (s -> f t) -> a -> f b) lenses with getter/setter pairs, although I
>>> haven't worked through the details yet so don't know either way.
>>>
>>> So, my question is: what is the advantage of representing lenses in
>>> the way that they are?
>>>
>>> Many thanks,
>>>
>>> David
>>> _______________________________________________
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe at haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list