sidnt / zionotes

⸮ 🔴zio notes | zio nursery 🔵?
0 stars 0 forks source link

Lenses, Folds and Traversals / Edward Kmett #12

Open sidnt opened 4 years ago

sidnt commented 4 years ago

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

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?

sidnt commented 4 years ago

some common sense laws on these operations