Skip to content

Commit

Permalink
Merge pull request #41 from melange-re/melange-4
Browse files Browse the repository at this point in the history
Upgrade melange from 3.0.0-51 to 4.0.0-51
  • Loading branch information
feihong authored May 22, 2024
2 parents a74a159 + 5462ac3 commit f0004ba
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 89 deletions.
4 changes: 2 additions & 2 deletions docs/better-burgers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ a number of syntactic and practical differences between them:
types.

The runtime representation of a record is a [plain JavaScript
object](https://melange.re/v3.0.0/communicate-with-javascript.html#data-types-and-runtime-representation),
object](https://melange.re/v4.0.0/communicate-with-javascript.html#data-types-and-runtime-representation),
the same as for a `Js.t` object.

::: info
Expand Down Expand Up @@ -365,7 +365,7 @@ and [demo](https://react-book.melange.re/demo/src/better-burgers/) for this chap
```

See this [playground
snippet](https://melange.re/v3.0.0/playground/?language=Reason&code=Ly8gVXNlIGEgcmFuZG9tIHZhcmlhYmxlIHNvIGZ1bmN0aW9uIGludm9jYXRpb25zIGFyZW4ndCBvcHRpbWl6ZWQgYXdheQpsZXQgYyA9IFJhbmRvbS5pbnQoMTApOwoKbGV0IGFkZCA9ICh4LCB5LCB6KSA9PiB4ICsgeSArIHo7CkpzLmxvZyhhZGQoMSwgMiwgYykpOwoKLy8gQW4gZXF1aXZhbGVudCBkZWZpbml0aW9uIHRoYXQgZXhwbGljaXRseSByZXR1cm5zIGZ1bmN0aW9uczoKbGV0IGV4cGxpY2l0QWRkID0geCA9PiB5ID0%2BIHogPT4geCArIHkgKyB6OwpKcy5sb2coZXhwbGljaXRBZGQoMSwgMiwgYykpOwovLyBDb25jZXB0dWFsbHksIHRoZXJlIGFyZSBtdWx0aXBsZSBmdW5jdGlvbiBpbnZvY2F0aW9ucy4gQnV0IGluIHRoZSBKUyBvdXRwdXQsCi8vIGl0J3MgYSBzaW5nbGUgZnVuY3Rpb24gY2FsbC4KSnMubG9nKGV4cGxpY2l0QWRkKDEpKDIpKGMpKTs%3D&live=off)
snippet](https://melange.re/v4.0.0/playground/?language=Reason&code=Ly8gVXNlIGEgcmFuZG9tIHZhcmlhYmxlIHNvIGZ1bmN0aW9uIGludm9jYXRpb25zIGFyZW4ndCBvcHRpbWl6ZWQgYXdheQpsZXQgYyA9IFJhbmRvbS5pbnQoMTApOwoKbGV0IGFkZCA9ICh4LCB5LCB6KSA9PiB4ICsgeSArIHo7CkpzLmxvZyhhZGQoMSwgMiwgYykpOwoKLy8gQW4gZXF1aXZhbGVudCBkZWZpbml0aW9uIHRoYXQgZXhwbGljaXRseSByZXR1cm5zIGZ1bmN0aW9uczoKbGV0IGV4cGxpY2l0QWRkID0geCA9PiB5ID0%2BIHogPT4geCArIHkgKyB6OwpKcy5sb2coZXhwbGljaXRBZGQoMSwgMiwgYykpOwovLyBDb25jZXB0dWFsbHksIHRoZXJlIGFyZSBtdWx0aXBsZSBmdW5jdGlvbiBpbnZvY2F0aW9ucy4gQnV0IGluIHRoZSBKUyBvdXRwdXQsCi8vIGl0J3MgYSBzaW5nbGUgZnVuY3Rpb24gY2FsbC4KSnMubG9nKGV4cGxpY2l0QWRkKDEpKDIpKGMpKTs%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)
for more details.
14 changes: 7 additions & 7 deletions docs/better-sandwiches/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ put shorter branches before longer branches:

The approach using `Js.Array.join` works, but readability could be improved by
using a [quoted string literal with the quoted string identifier
`j`](https://melange.re/v3.0.0/communicate-with-javascript.html#strings):
`j`](https://melange.re/v4.0.0/communicate-with-javascript.html#strings):

<<< Item.re#to-emoji-j-string-literal{5-13}

Expand All @@ -149,7 +149,7 @@ multi-line expressions in branches unless you add `{}` around them.

The OCaml standard library also provides a type-safe way to do string
interpolation in the form of the
[Printf.sprintf](https://melange.re/v3.0.0/api/re/melange/Stdlib/Printf/index.html#val-sprintf)
[Printf.sprintf](https://melange.re/v4.0.0/api/re/melange/Stdlib/Printf/index.html#val-sprintf)
function:

<<< Item.re#to-emoji-sprintf
Expand All @@ -159,7 +159,7 @@ literals:

- Since it's just a function, you can pass expressions into it
- It supports [conversion
specifications](https://melange.re/v3.0.0/api/re/melange/Stdlib/Printf/index.html#val-fprintf)
specifications](https://melange.re/v4.0.0/api/re/melange/Stdlib/Printf/index.html#val-fprintf)
like `%s`, `%i`, `%d`, etc which concisely handle basic string conversion
logic for all primitive data types. This can often make your code shorter and
easier to understand.
Expand Down Expand Up @@ -256,7 +256,7 @@ added is cheaper or more expensive *depending on the day of the week*.
::: details Hint 1

Look at the functions in the
[Js.Date](https://melange.re/v3.0.0/api/re/melange/Js/Date/) module.
[Js.Date](https://melange.re/v4.0.0/api/re/melange/Js/Date/) module.

:::

Expand Down Expand Up @@ -307,20 +307,20 @@ let player: Js.t({..}) = {

Use `Printf.sprintf` instead and improve the program as suggested by the
comments. You can edit the program interactively in [Melange
Playground](https://melange.re/v3.0.0/playground/?language=Reason&code=bGV0IGNvbXB1dGUgPSAoYSwgYikgPT4gKGEgKy4gMTAuKSAvLiBiOwoKLy8gUmV3cml0ZSB1c2luZyBQcmludGYuc3ByaW50ZiwgbGltaXQgcmVzdWx0IHRvIDMgZGVjaW1hbCBwbGFjZXMKbGV0IHJlc3VsdCA9IGNvbXB1dGUoNDAuLCA0Ny4pIHw%2BIHN0cmluZ19vZl9mbG9hdDsKSnMubG9nKHtqfHJlc3VsdCB0byAzIGRlY2ltYWwgcGxhY2VzID0gJChyZXN1bHQpfGp9KTsKCi8vIFJld3JpdGUgdXNpbmcgUHJpbnRmLnNwcmludGYKbGV0IHBsYXllcjogSnMudCh7Li59KSA9IHsKICAibmFtZSI6ICJXaWxidXIiLAogICJsZXZlbCI6IDkwMDEyMzQsCiAgImltbW9ydGFsIjogZmFsc2UsCn07CnsKICBsZXQgbmFtZSA9IHBsYXllciMjbmFtZTsKICAvLyBib251czogdXNlIHRoZSBmbGFnIHRoYXQgbWFrZXMgbG9uZyBudW1iZXJzIG1vcmUgcmVhZGFibGUKICBsZXQgbGV2ZWwgPSBwbGF5ZXIjI2xldmVsIHw%2BIHN0cmluZ19vZl9pbnQ7IAogIGxldCBpbW1vcnRhbCA9IHBsYXllciMjaW1tb3J0YWwgfD4gc3RyaW5nX29mX2Jvb2w7CiAgSnMubG9nKHtqfFBsYXllcjogbmFtZT0kKG5hbWUpLCBsZXZlbD0kKGxldmVsKSwgaW1tb3J0YWw9JChpbW1vcnRhbCl8an0pOwp9Owo%3D&live=off).
Playground](https://melange.re/v4.0.0/playground/?language=Reason&code=bGV0IGNvbXB1dGUgPSAoYSwgYikgPT4gKGEgKy4gMTAuKSAvLiBiOwoKLy8gUmV3cml0ZSB1c2luZyBQcmludGYuc3ByaW50ZiwgbGltaXQgcmVzdWx0IHRvIDMgZGVjaW1hbCBwbGFjZXMKbGV0IHJlc3VsdCA9IGNvbXB1dGUoNDAuLCA0Ny4pIHw%2BIHN0cmluZ19vZl9mbG9hdDsKSnMubG9nKHtqfHJlc3VsdCB0byAzIGRlY2ltYWwgcGxhY2VzID0gJChyZXN1bHQpfGp9KTsKCi8vIFJld3JpdGUgdXNpbmcgUHJpbnRmLnNwcmludGYKbGV0IHBsYXllcjogSnMudCh7Li59KSA9IHsKICAibmFtZSI6ICJXaWxidXIiLAogICJsZXZlbCI6IDkwMDEyMzQsCiAgImltbW9ydGFsIjogZmFsc2UsCn07CnsKICBsZXQgbmFtZSA9IHBsYXllciMjbmFtZTsKICAvLyBib251czogdXNlIHRoZSBmbGFnIHRoYXQgbWFrZXMgbG9uZyBudW1iZXJzIG1vcmUgcmVhZGFibGUKICBsZXQgbGV2ZWwgPSBwbGF5ZXIjI2xldmVsIHw%2BIHN0cmluZ19vZl9pbnQ7IAogIGxldCBpbW1vcnRhbCA9IHBsYXllciMjaW1tb3J0YWwgfD4gc3RyaW5nX29mX2Jvb2w7CiAgSnMubG9nKHtqfFBsYXllcjogbmFtZT0kKG5hbWUpLCBsZXZlbD0kKGxldmVsKSwgaW1tb3J0YWw9JChpbW1vcnRhbCl8an0pOwp9Owo%3D&live=off).

::: details Hint

Consult the [conversion specification
documentation](https://melange.re/v3.0.0/api/re/melange/Stdlib/Printf/index.html#val-fprintf).
documentation](https://melange.re/v4.0.0/api/re/melange/Stdlib/Printf/index.html#val-fprintf).

:::

::: details Solution

After replacing the `{j||j}` quoted string literals with
`Printf.sprintf` and improving it a bit, you might end up with something [like
this](https://melange.re/v3.0.0/playground/?language=Reason&code=bGV0IGNvbXB1dGUgPSAoYSwgYikgPT4gKGEgKy4gMTAuKSAvLiBiOwoKLy8gUmV3cml0ZSB1c2luZyBQcmludGYuc3ByaW50ZiwgbGltaXQgcmVzdWx0IHRvIDMgZGVjaW1hbCBwbGFjZXMKSnMubG9nKAogIFByaW50Zi5zcHJpbnRmKCJyZXN1bHQgdG8gMyBkZWNpbWFsIHBsYWNlcyA9ICUwLjNmIiwgY29tcHV0ZSg0MC4sIDQ3LikpLAopOwoKLy8gUmV3cml0ZSB1c2luZyBQcmludGYuc3ByaW50ZgpsZXQgcGxheWVyOiBKcy50KHsuLn0pID0gewogICJuYW1lIjogIldpbGJ1ciIsCiAgImxldmVsIjogOTAwMTIzNCwKICAiaW1tb3J0YWwiOiBmYWxzZSwKfTsKSnMubG9nKAogIFByaW50Zi5zcHJpbnRmKAogICAgIlBsYXllcjogbmFtZT0lcywgbGV2ZWw9JSNkLCBpbW1vcnRhbD0lQiIsCiAgICBwbGF5ZXIjI25hbWUsCiAgICBwbGF5ZXIjI2xldmVsLAogICAgcGxheWVyIyNpbW1vcnRhbCwKICApLAopOwo%3D&live=off).
this](https://melange.re/v4.0.0/playground/?language=Reason&code=bGV0IGNvbXB1dGUgPSAoYSwgYikgPT4gKGEgKy4gMTAuKSAvLiBiOwoKLy8gUmV3cml0ZSB1c2luZyBQcmludGYuc3ByaW50ZiwgbGltaXQgcmVzdWx0IHRvIDMgZGVjaW1hbCBwbGFjZXMKSnMubG9nKAogIFByaW50Zi5zcHJpbnRmKCJyZXN1bHQgdG8gMyBkZWNpbWFsIHBsYWNlcyA9ICUwLjNmIiwgY29tcHV0ZSg0MC4sIDQ3LikpLAopOwoKLy8gUmV3cml0ZSB1c2luZyBQcmludGYuc3ByaW50ZgpsZXQgcGxheWVyOiBKcy50KHsuLn0pID0gewogICJuYW1lIjogIldpbGJ1ciIsCiAgImxldmVsIjogOTAwMTIzNCwKICAiaW1tb3J0YWwiOiBmYWxzZSwKfTsKSnMubG9nKAogIFByaW50Zi5zcHJpbnRmKAogICAgIlBsYXllcjogbmFtZT0lcywgbGV2ZWw9JSNkLCBpbW1vcnRhbD0lQiIsCiAgICBwbGF5ZXIjI25hbWUsCiAgICBwbGF5ZXIjI2xldmVsLAogICAgcGxheWVyIyNpbW1vcnRhbCwKICApLAopOwo%3D&live=off).

:::

Expand Down
24 changes: 12 additions & 12 deletions docs/burger-discounts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ is no second burger, it returns `None`.

The functions used in `Discount.getFreeBurger` are:

- [Js.Array.sortInPlaceWith](https://melange.re/v3.0.0/api/re/melange/Js/Array/index.html#val-sortInPlaceWith)
- [Js.Array.sortInPlaceWith](https://melange.re/v4.0.0/api/re/melange/Js/Array/index.html#val-sortInPlaceWith)
takes a callback function `~f` with type signature `('a, 'a) => int` (accept
two arguments of the same type and return `int`). It's used to sort the items
by price (highest to lowest).
- [Stdlib.compare](https://melange.re/v3.0.0/api/re/melange/Stdlib/#val-compare)
- [Stdlib.compare](https://melange.re/v4.0.0/api/re/melange/Stdlib/#val-compare)
has type signature `('a, 'a) => int`. It's a polymorphic function capable of
comparing many types, including `bool`, `int`, `string`, etc. Note that you
can always just write `compare` instead of `Stdlib.compare`, because the
[`Stdlib` module is always opened by
default](https://melange.re/v3.0.0/api/re/melange/Stdlib/).
- [Js.Array.filter](https://melange.re/v3.0.0/api/re/melange/Js/Array/#val-filter)
default](https://melange.re/v4.0.0/api/re/melange/Stdlib/).
- [Js.Array.filter](https://melange.re/v4.0.0/api/re/melange/Js/Array/#val-filter)
takes a callback function `~f` with type signature `'a => bool`. It's used to
make sure all items in the `burgers` array are all burgers.

Expand Down Expand Up @@ -216,7 +216,7 @@ return value is `()` (the [unit
value](https://reasonml.github.io/docs/en/overview#unit)). However, inside this
test, we are calling `Discount.getFreeBurger` to test its side effects, so the
return value isn't needed; as such, we can explicitly discard it by using
[Stdlib.ignore](https://melange.re/v3.0.0/api/re/melange/Stdlib/#val-ignore)[^2]:
[Stdlib.ignore](https://melange.re/v4.0.0/api/re/melange/Stdlib/#val-ignore)[^2]:

```reason
Discount.getFreeBurger(items) |> ignore;
Expand Down Expand Up @@ -278,7 +278,7 @@ contains all the items, are turned into JS arrays.
Variant constructors in the runtime don't always have the `TAG` field. That
field only appears when there's more than one variant constructor with an
argument. See [Data types and runtime
representation](https://melange.re/v3.0.0/communicate-with-javascript.html#data-types-and-runtime-representation)
representation](https://melange.re/v4.0.0/communicate-with-javascript.html#data-types-and-runtime-representation)
for more details.

:::
Expand Down Expand Up @@ -363,8 +363,8 @@ In OCaml, the array access operator `[]` is just a function call. That is,
`burger[0]` is completely equivalent to `Array.get(burger, 0)`.

Since the [`Stdlib` module is opened by
default](https://melange.re/v3.0.0/api/re/melange/Stdlib/), the
[Stdlib.Array.get](https://melange.re/v3.0.0/api/re/melange/Stdlib/Array/#val-get)
default](https://melange.re/v4.0.0/api/re/melange/Stdlib/), the
[Stdlib.Array.get](https://melange.re/v4.0.0/api/re/melange/Stdlib/Array/#val-get)
function is used for `Array.get`, but it's possible to override this by defining
our own `Array` module. Add a new file `src/order-confirmation/Array.re`:

Expand Down Expand Up @@ -416,7 +416,7 @@ variable, e.g.
<<< Discount.re#return-variant-at-end

See [full example on Melange
Playground](https://melange.re/v3.0.0/playground/?language=Reason&code=bGV0IGNpcGhlckdyZWV0aW5nID0gbmFtZSA9PiB7CiAgc3dpdGNoIChTdHJpbmcudHJpbShuYW1lKSkgewogIHwgIiIgPT4gTm9uZQogIHwgbmFtZSA9PgogICAgbGV0IHJlc3VsdCA9CiAgICAgIG5hbWUKICAgICAgfD4gU3RyaW5nLnNwbGl0X29uX2NoYXIoJyAnKQogICAgICB8PiBMaXN0Lm1hcChTdHJpbmcubWFwKGMgPT4gYyB8PiBDaGFyLmNvZGUgfD4gKCspKDEpIHw%2BIENoYXIuY2hyKSkKICAgICAgfD4gU3RyaW5nLmNvbmNhdCgiICIpCiAgICAgIHw%2BIFN0cmluZy5jYXQoIkhlbGxvLCAiKTsKCiAgICBTb21lKHJlc3VsdCk7CiAgfTsKfTsKCkpzLmxvZyhjaXBoZXJHcmVldGluZygiIikpOwpKcy5sb2coY2lwaGVyR3JlZXRpbmcoIlhhdmllciBMZXJveSIpKTsK&live=off).
Playground](https://melange.re/v4.0.0/playground/?language=Reason&code=bGV0IGNpcGhlckdyZWV0aW5nID0gbmFtZSA9PiB7CiAgc3dpdGNoIChTdHJpbmcudHJpbShuYW1lKSkgewogIHwgIiIgPT4gTm9uZQogIHwgbmFtZSA9PgogICAgbGV0IHJlc3VsdCA9CiAgICAgIG5hbWUKICAgICAgfD4gU3RyaW5nLnNwbGl0X29uX2NoYXIoJyAnKQogICAgICB8PiBMaXN0Lm1hcChTdHJpbmcubWFwKGMgPT4gYyB8PiBDaGFyLmNvZGUgfD4gKCspKDEpIHw%2BIENoYXIuY2hyKSkKICAgICAgfD4gU3RyaW5nLmNvbmNhdCgiICIpCiAgICAgIHw%2BIFN0cmluZy5jYXQoIkhlbGxvLCAiKTsKCiAgICBTb21lKHJlc3VsdCk7CiAgfTsKfTsKCkpzLmxvZyhjaXBoZXJHcmVldGluZygiIikpOwpKcy5sb2coY2lwaGVyR3JlZXRpbmcoIlhhdmllciBMZXJveSIpKTsK&live=off).

---

Expand Down Expand Up @@ -469,7 +469,7 @@ Also refactor the "failure" pattern match so there's no wildcard.

::: details Hint

Use [Js.Array.map](https://melange.re/v3.0.0/api/re/melange/Js/Array/#val-map)
Use [Js.Array.map](https://melange.re/v4.0.0/api/re/melange/Js/Array/#val-map)

:::

Expand Down Expand Up @@ -501,7 +501,7 @@ topping. Add these new tests to `DiscountTests` and make sure they pass:

::: details Hint

Use [Js.Array.some](https://melange.re/v3.0.0/api/re/melange/Js/Array/#val-some)
Use [Js.Array.some](https://melange.re/v4.0.0/api/re/melange/Js/Array/#val-some)

:::

Expand Down Expand Up @@ -554,6 +554,6 @@ and [demo](https://react-book.melange.re/demo/src/burger-discounts/) for this ch
approach.

[^3]: Technically [`option` is a
variant](https://melange.re/v3.0.0/api/re/melange/Stdlib/Option/#type-t),
variant](https://melange.re/v4.0.0/api/re/melange/Stdlib/Option/#type-t),
but Melange treats them as a special case---`option` values are never
represented as JS objects in the runtime.
16 changes: 8 additions & 8 deletions docs/celsius-converter-exception/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ haven't quite gotten used to OCaml syntax yet.
If we enter a value with a lot of decimals in it, e.g. `21.1223456`, we'll
get a Fahrenheit value with a lot of decimals in it as well. We can limit the
number of decimals in the converted value using
[Js.Float.toFixed](https://melange.re/v3.0.0/api/re/melange/Js/Float/index.html#val-toFixed):
[Js.Float.toFixed](https://melange.re/v4.0.0/api/re/melange/Js/Float/index.html#val-toFixed):

<<< Snippets.re#fixed-precision{8,11}

`Js.Float.toFixed` is a function that has one positional argument
and one [labeled
argument](https://melange.re/v3.0.0/communicate-with-javascript.html#labeled-arguments).
argument](https://melange.re/v4.0.0/communicate-with-javascript.html#labeled-arguments).
In this case, the labeled argument is named `digits` and it's receiving a value
of `2`. It's not possible to pass in the value of a labeled argument without
using the `~label=value` syntax. We'll see more of labeled arguments in the
Expand Down Expand Up @@ -146,7 +146,7 @@ Try changing `{js|°C = |js}` to `"°C = "`.

Changing it to `"°C = "` will result in a bit of gibberish being rendered in
the browser: `°C`. We can't rely on normal OCaml strings to [deal with Unicode
correctly](https://melange.re/v3.0.0/communicate-with-javascript.html#strings),
correctly](https://melange.re/v4.0.0/communicate-with-javascript.html#strings),
so any string that contains non-ASCII text must be delimited using `{js||js}`
and not `""`. This kind of string constant is called a `{js||js}` *quoted string
literal* and it is specific to Melange, meaning it is not available in native
Expand Down Expand Up @@ -229,11 +229,11 @@ Js.log(addFive(10));
```

What do you think it outputs? Run it in [Melange
Playground](https://melange.re/v3.0.0/playground) to confirm your hypothesis.
Playground](https://melange.re/v4.0.0/playground) to confirm your hypothesis.

::: details Solution

Playground: [Define an addFive function using partial application](https://melange.re/v3.0.0/playground/?language=Reason&code=bGV0IGFkZEZpdmUgPSAoKykoNSk7CkpzLmxvZyhhZGRGaXZlKDIpKTsKSnMubG9nKGFkZEZpdmUoNykpOwpKcy5sb2coYWRkRml2ZSgxMCkpOw%3D%3D&live=off)
Playground: [Define an addFive function using partial application](https://melange.re/v4.0.0/playground/?language=Reason&code=bGV0IGFkZEZpdmUgPSAoKykoNSk7CkpzLmxvZyhhZGRGaXZlKDIpKTsKSnMubG9nKGFkZEZpdmUoNykpOwpKcy5sb2coYWRkRml2ZSgxMCkpOw%3D%3D&live=off)

:::

Expand All @@ -244,15 +244,15 @@ that result to binary.
::: details Hint

Use the
[Js.Int.toString](https://melange.re/v3.0.0/api/re/melange/Js/Int/#val-toString)
[Js.Int.toString](https://melange.re/v4.0.0/api/re/melange/Js/Int/#val-toString)
function.

:::

::: details Solution

Playground: [Define a function that subtracts from 10 and converts to
binary](https://melange.re/v3.0.0/playground/?language=Reason&code=bGV0IGNvb2xGdW5jdGlvbiA9IHggPT4geCB8PiAoKC0pKDEwKSkgfD4gSnMuSW50LnRvU3RyaW5nKH5yYWRpeD0yKTsKSnMubG9nKGNvb2xGdW5jdGlvbigxKSk7CkpzLmxvZyhjb29sRnVuY3Rpb24oNSkpOw%3D%3D&live=off)
binary](https://melange.re/v4.0.0/playground/?language=Reason&code=bGV0IGNvb2xGdW5jdGlvbiA9IHggPT4geCB8PiAoKC0pKDEwKSkgfD4gSnMuSW50LnRvU3RyaW5nKH5yYWRpeD0yKTsKSnMubG9nKGNvb2xGdW5jdGlvbigxKSk7CkpzLmxvZyhjb29sRnVuY3Rpb24oNSkpOw%3D%3D&live=off)

:::

Expand All @@ -266,5 +266,5 @@ and [demo](https://react-book.melange.re/demo/src/celsius-converter-exception/)

[^1]:
See [Using Js.t
objects](https://melange.re/v3.0.0/communicate-with-javascript.html#using-js-t-objects) for more
objects](https://melange.re/v4.0.0/communicate-with-javascript.html#using-js-t-objects) for more
details.
8 changes: 4 additions & 4 deletions docs/celsius-converter-option/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ let map = (func, option) =>

You may be interested in browsing the many other helper functions related to
`option` in the standard library's [Option
module](https://melange.re/v3.0.0/api/re/melange/Stdlib/Option/).
module](https://melange.re/v4.0.0/api/re/melange/Stdlib/Option/).

At this point, your switch expression might look like this:

Expand Down Expand Up @@ -132,7 +132,7 @@ nesting of conditionals to a minimum and making your code more readable.
Hooray! Our Celsius converter is finally complete. Later, we'll see how to
[create a component that can convert back and forth between Celsius and
Fahrenheit](/todo). But first, we'll explore [Dune, the build
system](https://melange.re/v3.0.0/build-system.html) used by Melange.
system](https://melange.re/v4.0.0/build-system.html) used by Melange.

## Overview

Expand Down Expand Up @@ -176,14 +176,14 @@ Add another `Some(fahrenheit)` branch with a `when` guard:
:::

<b>3.</b> Use
[Js.Float.fromString](https://melange.re/v3.0.0/api/re/melange/Js/Float/#val-fromString)
[Js.Float.fromString](https://melange.re/v4.0.0/api/re/melange/Js/Float/#val-fromString)
instead of `float_of_string_opt` to parse a string to float. Note that
`Js.Float.fromString` does not return `None` if it fails to parse a string to a
valid float.

::: details Hint

Use [Js.Float.isNaN](https://melange.re/v3.0.0/api/re/melange/Js/Float/#val-isNaN).
Use [Js.Float.isNaN](https://melange.re/v4.0.0/api/re/melange/Js/Float/#val-isNaN).

:::

Expand Down
4 changes: 2 additions & 2 deletions docs/counter/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ comes from the name of the module.
The `make` function has the type `unit => React.element`, meaning it takes `()`
as the only argument and returns an object of type `React.element`. You'll need
to decorate `make` with the
[attribute](https://melange.re/v3.0.0/communicate-with-javascript.html#attributes)
[attribute](https://melange.re/v4.0.0/communicate-with-javascript.html#attributes)
`@react.component`. We'll go into the details [later](/todo), but for now
let's just say that `@react.component` is there to reduce boilerplate and make
our code more readable and easier to maintain.
Expand Down Expand Up @@ -102,7 +102,7 @@ read from left to right:
{counter |> Int.to_string |> React.string}
```

This uses the [pipe last operator](https://melange.re/v3.0.0/communicate-with-javascript.html#pipe-last),
This uses the [pipe last operator](https://melange.re/v4.0.0/communicate-with-javascript.html#pipe-last),
which is useful for chaining function calls.

## Basic styling
Expand Down
2 changes: 1 addition & 1 deletion docs/cram-tests/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Now that you have a set of unit tests for sandwich-related logic, you realize it
would be nice to have some unit tests for burger-related logic as well. But
adding a new command to your `test` npm script doesn't feel like The OCaml Way,
so you hop on the [Reason Discord
chatroom](https://melange.re/v3.0.0/community.html#community) to ask for advice.
chatroom](https://melange.re/v4.0.0/community.html#community) to ask for advice.
MonadicFanatic1984 once again comes to your aid and points you toward *cram
tests*.

Expand Down
Loading

0 comments on commit f0004ba

Please sign in to comment.