Machine-checked explicit state: An arrow in the heart of complex web apps
blog.reifyworks.com
blog.reifyworks.com
If you have a big global model, with messages modifying that model, then eventually you're going to notice that many places in that model are similar. E.g., widget state for identical widgets on different parts of the page. So you tag the messages that pertain to a particular widget with some kind of coordinate into the global model, and then you call generic widget code with the local widget state as an argument, and the message, to produce a new local widget state. Congratulations, you've reinvented objects.
Every time you use an HTML input tag, you are using an abstraction over state, and the first time you need access to the input element's cursor and selection, you realize you've been pretending the element had less state than it had, which is a pretty useful thing to do.
If I can write a form component that needs an "editor for a string" component, specified as a type, and fill that need with a "fancy editor for a string" component that has a more elaborate model that I can abstract away, then I think we're in business, but I can't quite picture how that would work.
Objects are opaque handles to a state machine which contains an undefined state, that's not what Elm is. Elm is pure, so you only define transformations, and compose them together. The runtime system keeps track of state, not you as the programmer. You just define transformations from one or more types to another one, compose them together to form descriptions of how to transform one, e.g., UI layout into another, connect it to user input, and everything is guaranteed to fit together (unless you ignore important warnings). You no longer keep track of state, you define functions that transform one piece of information into another, and define functions that render a static piece of information into a UI.
I don't understand this. There's a lot of things that is "available in the application to your users" that is outside of the control of Elm - for example, the text selection, scroll position, window position and resolution...
> With Elm, there’s no place to "hide" state in your application that aren’t threaded through the type checker
State isn't so much hidden as collaborative. Multiple components participate and have a need to store independent UI state. For example, a table component might want to control scrolling, filtering, and selection state, while delegating populating the row data to the app.
Is it possible in Elm to allow separate software components to maintain their own independent states, without requiring some god-component to have global knowledge?
State being collaborative is precisely the problem. If all the components owned important state, they would need to share it with each other. This gets real complicated very quickly, especially when multiple parts of the app need to change that state.
So the main proposition of Elm is exactly that separate components should not hold important state and whatever that needs to be shared should be centralized and modified in one place. Which sounds like the God Object antipattern, but is not, mainly because you can only change the state indirectly, by sending well-defined messages.
I see they've invented a new name to label the innovation as such.