Closed dgreensp closed 2 years ago
a) there are some changes I made in the process of writing a tutorial, so the example code shown in early parts of the tutorial differs from later parts of the tutorial. In those cases, I called out the change explicitly in the later posts. I think the | in matches is one example of that. b) there are some changes I made after I finished the tutorial just to make cubiml more convenient, but which didn't seem significant enough to bother writing a new blog post about. For example, I implemented destructuring syntax. Changing associativity of call expressions was probably one of those as well.
The match name thing looks like a bug, so I'll look into changing the example code later to avoid confusing people. Thanks for reporting this.
I added notes to the blog about the updated cubiml syntax as you suggested. Thanks for the feedback!
I want to mention these things while they are still in my head from going through the tutorial (I'm on part 3). I think it could be helpful to edit or insert small notes into the tutorial. Also let me know if I'm incorrect about any of these, as they are subtle.
Part 3: Match expressions The loop checks for duplicate "names," throwing a "Repeated match case" error. Duplicate variable names doesn't seem like it should be a problem. Maybe duplicate tags? In the GitHub code, exhaustiveness checking has replaced this check, but for the tutorial, I think the correct thing might be checking for duplicate tags, not duplicate names.
Part 2: Parsing "Call" In the grammar in the tutorial,
Call
is parsed asCallExpr CaseExpr
, whereCallExpr
isCaseExpr | Call
. That meansa b c
will be parsed as(a b) c
. In the GitHub implementation, there is a note thata b c
is intentionally parsed asa (b c)
, unlike in Ocaml, and the grammar bears this out. This is probably just something that was changed in the codebase after writing the tutorial, but it confused me for a minute when implementing the grammar from the tutorial, having read the Cubiml docs and played with the demo. It might warrant a note in the tutorial. I chose to make my parser match the current codebase.Match syntax This is another mere difference between the tutorial and the codebase, but in the tutorial, there is no
|
before the first case in a match expression, while in the current codebase, it is required. It may not seem like a big deal, but because there is not a lot of Cubiml code in the tutorial, I find myself looking to the GitHub README for examples of the syntax, and it's tricky when it's different. Maybe both this and the previous point code be mentioned in a note right after the grammar in Part 2.I can't wait to get to later topics like let polymorphism and flow typing! This tutorial is really like none other.