diku-dk / futhark

:boom::computer::boom: A data-parallel functional programming language
http://futhark-lang.org
ISC License
2.41k stars 166 forks source link

Feature Request: Splat / Rest Exprs for Records #2171

Closed entropylost closed 3 months ago

entropylost commented 3 months ago

If I have a large record, I'd like to be able to create a new record with some elements changed without having to write out all elements of the record. For example,

let a = {
  x = 1.0,
  y = 1.0,
  z  = 1.0,
} in { x = 2.0, ..a }

should be equivalent to

let a = {
  x = 1.0,
  y = 1.0,
  z  = 1.0,
} in { x = 2.0, y = a.y, z = a.z }

It seems like this was a feature a while back according to https://futhark-lang.org/blog/2017-03-06-futhark-record-system.html, but it seems to have been dropped and the current documentation does not state an alternative except use of with statements, but I would prefer to avoid the shadowing that it provides.

athas commented 3 months ago

with expressions to not shadow anything.. You'd write the above as let a = ... in a with x = 2.0.

entropylost commented 3 months ago

@athas huh, I suppose that does work. My issue with that is that I sometimes want to update multiple variables at once, but that's quite minor.

athas commented 3 months ago

You can chain with: a with x = 1 with y = 2.

entropylost commented 3 months ago

Alright thanks.