Here's an example of where record field pattern matching would make things
more straight forward:
case model.route of
Routes.Entry { mode } ->
if mode == Read then
(hex "FFFFFF")
else
(hex "f6f6f6")
_ ->
(hex "f6f6f6")
If we were able to pattern match on values within records, it could look
like this instead:
case model.route of
Routes.Entry { mode = Read } -> hex "ffffff"
_ -> hex "f6f6f6"
I think that's much more readable.
Without pattern matching, I had to repeat the value in the default case
twice, potentially leading to subtle bugs. I could do something like this
to avoid that:
let
default = hex "f6f6f6"
in
case model.route of
Routes.Entry { mode } ->
if mode == Read then
(hex "FFFFFF")
else
default
_ ->
default
But I think that's even less readable.
On Thursday, March 2, 2017 at 11:12:39 PM UTC-7, Richard Feldman wrote:
>
> There have been various discussions of potential ways to improve Elm's
> record update syntax. Evan commented that "(examples > design work) at this
> point" - any potential designs for syntax improvements would need to be run
> through a gauntlet of examples to see how well they'd work, so the first
> step in the process is to gather those examples.
>
> So let's collect a ton of different real-world examples! That will help
> guide the design process.
>
> If you've run into a record update that you felt was painful and could be
> improved in some way, please post it here! (Also, *please keep this
> thread for posting of examples* *only* - it'll be easier to link back
> here during design discussions if we can reference a clean thread of
> examples, as opposed to a mismash of examples interleaved with suggestions.)
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.