Hey there Richard. Ok, here were the items that got me a bit confused:
1.) You linked to this file, but the code that is in the actual tutorial doesn't match up (I assume cause you updated it at some point?). But either way, if someone wanted to download the file, it wouldn't match.
2.) Right after copying that opening file (right above the "Let's build this, shall we?" part, it asks you to build it, but that file won't build, and not because of the reasons you predict in the post. It doesn't build because we're missing some things.. a.) initialModel does not exist. And we also need to set "errors" on the initial model. So I would suggest doing this..
initialErrors =
{ username = "", password = "" }
initialModel =
{ username = "", password = "", errors = initialErrors }
instead of just the initialErrors
part.
b.) There's no update function. And so you can either add a placeholder one, or change the Html.App.program part of main
.
The former seems easier, so I would suggest adding a placeholder update function. Something like...
update msg model =
if True then
(model, Cmd.none)
else
(model, Cmd.none)
3.) Towards the end, we have this...
failureToMsg err =
{ msgType = "USERNAME_AVAILABLE", payload = "" }
However... this is just a record, and the Task.perform requires the argument to be a function, not a record. You mention this, but the code does not reflect it, and I totally didn't catch it until the compiler yelled at me. I ended up doing the following...
failureToMsg =
\ _ -> { msgType = "USERNAME_AVAILABLE", payload = "" }
But I'm not actually sure if that's the "elm way" to do things. So clarification on that would be great.
Otherwise, I think it's a good intro to doing just enough "real stuff" in Elm to get a feel for it.
As a separate part, I might include a quick section two to refactor it into more "best practices", like using the Union operator and case statements, as you allude to. Or to expand on it a little bit. In general, what I'm finding as I try to learn elm now is that there's very little out there to give guidance on how Elm works "in the wild". Like, some good example apps that show what the full story is like would be awesome!. I'm talking about routing, testing, nested views, etc. I suppose that's what your book is about, but if you know of anything I'd love to see it! (especially if it's since 0.17)