aesophia icon indicating copy to clipboard operation
aesophia copied to clipboard

Pointwise state modifications

Open radrow opened this issue 2 years ago • 3 comments

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}})

radrow avatar Sep 16 '22 08:09 radrow

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

radrow avatar Sep 16 '22 08:09 radrow

+1

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

brainiacfive avatar Sep 22 '22 08:09 brainiacfive

oh yeah, I like this one! :)

marc0olo avatar Sep 22 '22 14:09 marc0olo