You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Macro Lenses could allow really nice nested updates of immutable hierarchical structures. Like:
# tree for the source code (~1 + (2 + 3))x=BinOp(
left=UnaryOp(
op=Invert(),
operand=Num(n=1)
),
op=Add(),
right=BinOp(
left=Num(n=2),
op=Add(),
right=Num(n=3)
)
)
# converting it to the tree for (~3 + (2 + 3)# without lensesx1=x.copy(left=x.left.copy(operand=x.left.operand.copy(n=3)))
# with lensesx1=lens%x.left.operand.n.set(3)
# changing (~1 + (2 + 3)) to (~2 + (2 + 3)), by adding one to the previous value of the left item# without lensesx2=x.copy(left=x.left.copy(operand=x.left.operand.copy(n=x.left.operand.n+1)))
# with lensesx2=lens%x.left.operand.n.set(_+1)
# setting the value on the left to the sum of all values, giving (~6 + (2 + 3))# without lensesx3=x.copy(left=x.left.copy(operand=x.left.operand.copy(n=x.left.operand.n+x.right.right.n+x.right.left.n)))
# with lensesx3=lens%x.left.operand.n.set(_+_._.right.left.n+_._.right.right.n)
I think the last one is properly called a Zipper, but I'm not familiar enough with that branch of FP to say for sure.
The text was updated successfully, but these errors were encountered:
Macro Lenses could allow really nice nested updates of immutable hierarchical structures. Like:
I think the last one is properly called a Zipper, but I'm not familiar enough with that branch of FP to say for sure.
The text was updated successfully, but these errors were encountered: