-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add better burgers chapter #21
Conversation
ccf2bb5
to
b1e974a
Compare
See this [playground | ||
snippet](https://melange.re/v2.2.0/playground/?language=Reason&code=Ly8gVXNlIGEgcmFuZG9tIHZhcmlhYmxlIHNvIGZ1bmN0aW9uIGludm9jYXRpb25zIGFyZW4ndCBvcHRpbWl6ZWQgYXdheQpsZXQgYyA9IFJhbmRvbS5pbnQoMTApOwoKbGV0IGFkZCA9ICh4LCB5LCB6KSA9PiB4ICsgeSArIHo7CkpzLmxvZyhhZGQoMSwgMiwgYykpOwoKLy8gQW4gZXF1aXZhbGVudCBkZWZpbml0aW9uIHRoYXQgZXhwbGljaXRseSByZXR1cm5zIGZ1bmN0aW9uczoKbGV0IHJlYWxBZGQgPSB4ID0%2BIHkgPT4geiA9PiB4ICsgeSArIHo7CkpzLmxvZyhyZWFsQWRkKDEsIDIsIGMpKTsKLy8gQ29uY2VwdHVhbGx5LCB0aGVyZSBhcmUgbXVsdGlwbGUgZnVuY3Rpb24gZGVmaW5pdGlvbnM6CkpzLmxvZyhyZWFsQWRkKDEpKDIpKGMpKTs%3D&live=off) | ||
for an extended example and the [official OCaml | ||
docs](https://ocaml.org/docs/values-and-functions#types-of-functions-of-multiple-parameters) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if there's a better link that explains multiple argument functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome!
I wonder if the intro section with "Chapters and topics" should be updated? The table last item is "Styling with CSS":
| Styling with CSS | Styling the order confirmation using CSS | `mel.raw` extension node, `runtime_deps` field, `glob_files` term, `external`, `mel.module` attribute | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the intro section with "Chapters and topics" should be updated? The table last item is "Styling with CSS"
I plan to update Chapters and topics table in a separate PR
|
||
The compiler wouldn't complain but the ensuing logic would likely be wrong. | ||
|
||
The best approach here is to use the record itself as the input to the switch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find our previous thread about this (maybe it was somewhere in this old PR?), but I decided to go with switch expression without the backticks since it's more of a concept than just syntax, same as how I write if-else, ternary, etc without the backticks.
In mainstream languages that have pattern matching (C#, Swift, Java) they've mostly settled on calling this "switch". Python is the only mainstream language I know of which uses "match". But since "switch" is kind of an overloaded term, maybe I should use "pattern match expression" instead?
docs/better-burgers/index.md
Outdated
|
||
| Name | Type | Meaning | | ||
| ---- | ---- | ------- | | ||
| lettuce | bool | if `true`, include lettuce | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe this should be either
bool
or- boolean
?
Same with int: either int
or integer. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted to just put the field names and types in backticks in ad5f959
docs/better-burgers/index.md
Outdated
a number of syntactic and practical differences between them: | ||
|
||
- Record fields must be predefined | ||
- Records use `.` to access fields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Records use `.` to access fields | |
- Records use `.` to access fields, while `Js.t` values use `##` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in ad5f959
docs/better-burgers/index.md
Outdated
|
||
- Record fields must be predefined | ||
- Records use `.` to access fields | ||
- Records can be destructured and pattern matched) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Records can be destructured and pattern matched) | |
- Records can be destructured and pattern matched |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in ad5f959
docs/better-burgers/index.md
Outdated
- Record use [nominal | ||
typing](https://en.wikipedia.org/wiki/Nominal_type_system), while `Js.t` | ||
objects use [structural | ||
typing](https://en.wikipedia.org/wiki/Structural_type_system). This means that | ||
two record types with exactly the same fields are still considered different | ||
types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great 👍
Overview
Record types are like
Js.t
objects but their fields must be explicitlydefined
Js.t
objects are both JavaScript objects during runtimeYou can get the fields out of a record using destructuring and pattern
matching:
let
destructuring:It's common practice to group related types and functions into a submodule
Try not to ignore record fields when pattern matching on records. Instead of
Prefer
Assuming
c
andd
aren't used inside the branch.Try not to pattern match on tuples of more than 2 elements because it tends to
be hard to read