Discussion:
[elm-discuss] Curious about nested updates
Carlos De la Guardia
2017-05-04 01:18:46 UTC
Permalink
I was just reading past threads with proposals for new record-updating
syntax. I'm curious, does anyone know why the following update syntax is
problematic, or a good way to find out if it's problematic?

record =
{ a = 0
, b = { c = 0 }
, d = { e = { f = 0 } } }
, g = 0
}

newRecord =
{ record
| a = 1
, b.c = 2
, d.e.f = doSomething record.d.e.f
}
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Alex Lew
2017-05-09 02:08:21 UTC
Permalink
The rules are that in a record update, neither the record being updated (the thing to the left of the bar) nor the field names can have dots in them. In order to do nested record updates, you'll have to use `let...in...` to give simpler names to all your record's nested fields.

I believe the logic here is that nested records are generally bad design, but I'd love to see this explored more, as obviously, in other programming languages, we are all quite used to building data types out of other data types. Perhaps nested records are OK but trying to update multiple levels of a record at once is a sign of bad design?
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...