# Dynamic record updates

**URL:** <https://discourse.elm-lang.org/t/dynamic-record-updates/1198>\
**Category:** Learn\
**Created:** [April 30, 2018, 7:20pm UTC](https://discourse.elm-lang.org/t/dynamic-record-updates/1198 "2018-04-30T19:20:09Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![Sidney](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/sidney/32/3290_2.png) [@Sidney](https://discourse.elm-lang.org/u/Sidney)\
**Post date:** [May 1, 2018, 1:06am UTC](https://discourse.elm-lang.org/t/dynamic-record-updates/1198/11 "2018-05-01T01:06:23Z")

</div>

> [@rtfeldman](#):
>
> YMMV, but I thought I’d share how I got to a point where this did not bother me anymore! It’s possible you’ve been much more successful at this than I have, but I think the self-reflection exercise was well worth the time, and I’d encourage anyone to take an honest self-assessment of how these quests have turned out in the past.

I totally see where you’re coming from. I had a similar realization, the tools/applications/enhancements I attempt to make seem to take more time than the original task would have! But that doesn’t stop me from trying 😉

Lately, instead of sinking 20 hours into some improvement that isn’t even guaranteed to help, I’ll just spend an hour or two. If I like what I come up with, I’ll give it a shot. Maybe it isn’t perfect, but I try to improve it over time. Maybe I hate it – I likely didn’t fully understand the problem. In that case, I’ll just do the task when I need to, but continue to think in the back of my mind how it could be automated, or how the boilerplate could be reduced. Hopefully in the future I come up with something better.

* * *

Bringing it back to this thread’s topic, I think we have identified a problem (boilerplate in some circumstances). I’d like to consider solutions before conceding to live with it! I think the simplest solution is a _record updater_ syntax, to complement the _record accessor_ syntax. (I know this has been suggested before, and even in this thread!)

```
-- accessor
.x : { a | x : b } -> b

-- updater
^x : b -> { a | x : b } -> { a | x : b }

```

Now, is that perfect? Does it even help? No idea. I wish I could test it! If I knew more Haskell, I’d fork the compiler and add it in. At least to see how it _feels_ to use. (Maybe the arguments should be flipped? Maybe it should use a different symbol?)

Another problem I saw mentioned in this thread is the idea of wiring up, for example, form fields. Every field is tracked in the model, and updates need to come back and get set in the model. Very boilerplatey.

JavaScript, for example, has a lot of ways to deal repetitive code like this. You can pass around field names (ie object keys) as strings, and access fields on the fly (obj[keyName]). That allows you to store your fields in some kind of set or list, and dynamically access the correct one. Of course, JavaScript can’t do this in a type-safe way… can we do this in Elm? Well, I think @hecrj’s [form API idea/proposal](https://discourse.elm-lang.org/t/a-form-api-idea-proposal/1121) is a very good start (I recently used it in a project and found it prevents a lot of this type of boilerplate). But I feel like we can do something more at a language/syntax level.

I have a vague Idea in my mind that _macros_ of some kind might help, but I’m not sure what that would look like… personally, I’m still mulling over possible solutions, nothing solid at this point.

I’m eager to see what else we can come up with 🙂

---

_[View the full topic](https://discourse.elm-lang.org/t/dynamic-record-updates/1198)._
