Pointwise state modifications #416

Open
opened 2022-09-16 17:37:16 +09:00 by zxq9 · 3 comments
zxq9 commented 2022-09-16 17:37:16 +09:00 (Migrated from gitlab.com)

Created by: radrow

This would be a syntactic sugar that would possibly make it nicer to modify state fields (if it is a record, which is mostly the case).

record r = {val : int}
record state = {x : int, y : r}
stateful function f() =
  state.x = 21
  state.y.val = 37

which would desugar to

put(state{x = 21})
put(state{y = state.y{val = 37}})

and ideally to

put(state{x = 21, y = state.y{val = 37}})
*Created by: radrow* This would be a syntactic sugar that would possibly make it nicer to modify state fields (if it is a record, which is mostly the case). ``` record r = {val : int} record state = {x : int, y : r} stateful function f() = state.x = 21 state.y.val = 37 ``` which would desugar to ``` put(state{x = 21}) put(state{y = state.y{val = 37}}) ``` and ideally to ``` put(state{x = 21, y = state.y{val = 37}}) ```
zxq9 commented 2022-09-16 17:38:06 +09:00 (Migrated from gitlab.com)

Created by: radrow

Note that state modifications are still explicit, as one needs to refer to the state as lvalue.

*Created by: radrow* Note that state modifications are still explicit, as one needs to refer to the `state` as lvalue.
zxq9 commented 2022-09-22 17:46:50 +09:00 (Migrated from gitlab.com)

Created by: brainiacfive

+1

I thought the compiler optimizes multiple puts into one at any rate.

*Created by: brainiacfive* +1 I thought the compiler optimizes multiple puts into one at any rate.
zxq9 commented 2022-09-22 23:36:22 +09:00 (Migrated from gitlab.com)

Created by: marc0olo

oh yeah, I like this one! :)

*Created by: marc0olo* oh yeah, I like this one! :)
Sign in to join this conversation.
No Milestone
No project
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: QPQ-AG/sophia#416
No description provided.