in imperative code, we can easily RW to nested getters and setters way down
foo.bar.baz.qux += 10
in a functional setting, that's harder
Record updates are not very compositional.
there's a tony morris talk on lenses
lenses are in a way
getters and setters, put together in one object.
simplest form of a lens
we can view an a:A on an s:S
we can set, by taking an s:S and an a:A, that we want to set into it, to obtain a newS:S
doubt is the A structure present as A itself, in the S structure even? or is there an indirection in between? like is there a reader r: S => A which takes an S and composes an a:A from the information in S ?
whether it stores or whether it computes, that's not a concern expressed in the type though. the type is implementation agnostic. the type doesn't express what happens underneath. it only tells what type can go in and what type can come out.
but since the definition of lens in the previous para doesn't say anything of that sort, we can't assume that structure A exists, as a directly consumable value, in S, and that it is not a computation on S that builds an A from information underlying in S. same for setting. do we know, that there exists a node, a:A in s:S that is directly replaceable by a newA:A? or is it that, to set a newA into s, we'll invoke a handler handleA: (s:S, newA:A) => newS:S, which will unpack the newA to produce changes into the s to produce a newS?
in imperative code, we can easily RW to nested getters and setters way down
foo.bar.baz.qux += 10
in a functional setting, that's harderthere's a tony morris talk on lenses
lenses are in a way getters and setters, put together in one object. simplest form of a lens
a:A
on ans:S
s:S
and ana:A
, that we want to set into it, to obtain anewS:S
doubt is the A structure present as A itself, in the S structure even? or is there an indirection in between? like is there a reader
r: S => A
which takes an S and composes ana:A
from the information in S ?whether it stores or whether it computes, that's not a concern expressed in the type though. the type is implementation agnostic. the type doesn't express what happens underneath. it only tells what type can go in and what type can come out.
but since the definition of lens in the previous para doesn't say anything of that sort, we can't assume that structure A exists, as a directly consumable value, in S, and that it is not a computation on S that builds an A from information underlying in S. same for setting. do we know, that there exists a node,
a:A
ins:S
that is directly replaceable by anewA:A
? or is it that, to set anewA
into s, we'll invoke a handlerhandleA: (s:S, newA:A) => newS:S
, which will unpack the newA to produce changes into the s to produce a newS?