2015-01-05

Posted on January 5, 2015

So, can I do anything to improve how the bindings work in the todo app? From a brief scan of the packages linked from the GHCJS intros, I don’t see anything that would help.

For the most part, the problem is quite simple. I have two values of type State, and a binding is simply a function of the state and the id of a <span> element. We run the function on the old State and the new one, and if it’s changed we update the element.

There’s just one improvement to make to that: rather than dealing directly with the State, we should first pass it through an augmenting function that can memoize common subexpressions, such as length . stateTodos.

OR, we could not bother with that at all, and instead use a sane data structure that can calculate lengths in constant time. (And ClassyPrelude should make that quite simple, if I’ve understood properly, although for the purposes of the todo app I may not bother with that.)

So, I’m quite pleased with my newly invented Binding and Tweak structures, which capture some of the patterns used in the app. And now I’m being pulled in lots of different directions again (with never enough time).

I see the following options.

Although the former is very tempting, there are some yesod / GHCJS integration matters which I’m not happy with. For example, sharing JSON instances between GHCJS and yesod, and getting cabal to build both parts of the project. It would be nice to play with these in a toy environment.