Implications of storing functions in model or msg type

There have been two other discussions here asking a similar question

but I feel that there hasn’t been any comprehensive discussion about the implications of storing functions in the application model or msg type.

From what I’ve read, the following are implications with doing this:

  • Potentially harder to understand code (though perhaps not always?)
  • It prevents exporting debugger history (regardless if it’s the model or msg containing functions)
  • Using == on a data structure containing a function causes a runtime error
  • Prevents compiler optimizations (what kind of optimizations does the compiler do that are affected?)
  • Breaks hot reloading (at least, it does in create-elm-app but I haven’t tested other tools. Also I’m not sure if this is only a problem for storing functions in the model or the msg type also.)
  • It does not break Html.lazy due to lazy using reference equality

Are all these statements true? Are there things I’ve missed?


I don’t know about all of them, but at least these are true:

  • prevents exporting debugger history (this is why hot reloading breaks too)
  • prevents using == on Model values

It may or may not break lazy. If the function changes, for example by being partially applied with different arguments, then the reference is different and the view will be re-rendered.


This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.