I’ve been stalking the Elm project for a long while now, but only now sat down to get my hands dirty. Here I’ve tried to document my experiences as a newcomer, in case it’s useful to anyone.
Maybe eight months ago I jumped in headfirst and decided I’d compile elm from source so that I could contribute back right away. Unless you’re already steeped in the vagaries of cabal-install, I have to strongly recommend against this. Enough said
There’s a large number of breadcrumbs to the tutorial (http:/guide.elm-lang.org) so as I wandered off into stackoverflow or blogs I was lead back time and time again. That part is working great!
I read the tutorial linearly up till the “Code Editor” portion. I’m a VIM person, and I’m on a chromebook, so sublime is a nonstarter for me, or else I’d have used it and been on my merry way, I’m sure. Instead I made several hours-long detours into figuring out the vim plugin system afresh (moved from pathogen to vim8 native packaging) and encountering a bug, it looks like it’s actually lacking a maintainer currently. I’m using the fork that’s currently maintained by Zaptic because I found on several issues that fork was working better than mainline.
I really dislike the pattern of npm install -g
and instead I use linuxbrew and brew install yarn
and this little bash script that I source before getting to work with elm. I’m quite happy with this, and it means that my elm dabblings are completely sandboxed away from my system packages.
$ cat .activate.sh
#!/not/executable/bash
HERE="$(dirname "$(readlink -f "${BASH_SOURCE:-$0}")")"
eval "$(brew shellenv)"
yarn install
PATH="$HERE/node_modules/.bin:$PATH"
After a couple weeks of false starts related to vim configuration and yarn fuddling, I sat down with a goal: I want to make a pong-like bouncing ball. SVG seems like an obvious fit here, since I’ve only got one object and I don’t feel like doing pixel math or learning openGL today.
To animate the thing, it seems like waking up to update the position of the ball every frame is overkill, but the only thing better I could find was the [Web Animations API][1] and it seems like too much for me to take on currently. So I settled on using the mdgriffith/elm-style-animation package, which seems like it’s been performant-enough for a large number of people.
The final subproblem is collision detection. While simple x - left < width
math would have sufficed here, I went looking for a better solution. The [Intersection Observer API][2] does what I want and seems simple enough for me to deal with.
With some tech-stack decisions in hand I came back to elm. Here I made the mistake of skipping from the “Code Editor” section to the “Ports” section. I ran into several problems and bugs that would have been solved by reading “Javascript Interop” first. They were pretty surprising and annoying though, so I’ll note them here anyhow.
-
elm reactor
(which is used in the tutorial up till “Javascript Interop”) just completely [doesn’t work with ports][3]. Because the elm-reactor repo is archived, I can’t even leave a breadcrumb on that issue for the next person to bump into this. If elm reactor were enhanced to very simply detect a ports package and stop with an error, saying something along the lines of “hey you skipped the Javascript Interop page!”, that would have been the kind of pleasant error message Elm gives in other circumstances. -
Browser.sandbox
(again, used in the guide before Javascript Interop) also conflicts 100% with ports. The user-facing symptom is that app.ports is undefined, which made me think I was misunderstanding ports entirely and defining them wrong. If the resulting javascript object had some sort of smart object put in place at the .ports attribute, that would be a helpful breadcrumb. If the type system could infer that the user wants ports but will never get them (due to sandbox), that would be even better. There’s a similar-ish behavior already in place when a user defines a port module without any ports.
To be continued…
I’ll try to read the rest of the guide in-order this time!
[sic] Intentionally malformed due to “Sorry, new users can only put 2 links in a post.”
[1]: https:/developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API
[2]: https:/developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
[3]: https:/github.com/elm-lang/elm-reactor/issues/36