This took me longer than I expected it to, and looking back over the last couple of days worth of reading & coding, I'm kind of embarrassed at both how long it took and at not knowing why it took so long. I'm a JavaScript/Python/Clojure type, maybe it was the static typing. I'm also used to a REPL-heavy style of programming
where I test each piece in the browser/Node console before putting it in my code, and that worked for only a small piece of this app. Or most likely it was reading too much and trying to build a model of what my code ought to look like instead of just writing code and seeing how it breaks and iterating until I get something that works—time wasted by trying to avoid the way of the true noob.
I have a REST API that spits out the result of linguistics-style parsing of human-language sentences as JSON, which I wanted to get into my Elm app and displayed to some screen for inspection, and before moving on to using it. I read most of
http://elm-by-example.org, several articles on the "docs" section of the website including the one on interop (tasks), etc., and what motivated me to post this was realizing how I needed *four* pieces of documentation to get to here:
(1)
http://elm-lang.org/guide/reactivity#http-tasks to show how to use a mailbox, with `signal` and `address`, and a port, and the Http library (I was too fearful of using the TaskTutorial package).
(2)
http://package.elm-lang.org/packages/evancz/elm-http/2.0.0/#example showed me how to use Http.get and a decoder, instead of Http.getString (the zippopotamus example).
(3)
http://www.troikatech.com/blog/2015/08/17/decoding-larger-json-objects-in-elm showed me how to decode big JSON objects without objectN using this creative `appy` function mentioned there. And,
(4)
https://groups.google.com/d/msg/elm-discuss/CrXoz3bN0PQ/kx7Vpe5RbH4J that suggested using Text.asText which is now Graphics.Element.show for hello-worlding the Elm data to a screen.
I was able to use the REPL to build the sequence of nested JSON decoders, by pasting the JSON into the REPL. But for all the HTTP piping, I had to let the code run in elm-reactor—especially since I can't seem to make a port in the REPL (?).
I put my Elm code, example JSON, and test output at
https://gist.github.com/fasiha/2658d380a92c98e1af46 — it might be helpful to someone to see the handful of different pieces needed for this simple data processing, and I might get some valuable advice on my code and approach, and see if we can perhaps organize some documentation that speaks to this kind of relatively simple front-end JavaScript data loading & processing.
Thanks for reading! I'm having a great time with Elm, it's so fun—I look forward to reaching the same level with Elm as I am with regular JavaScript!