[rescript/en] update (#4947)

This commit is contained in:
Danny Yang 2024-05-18 11:20:04 -04:00 committed by GitHub
parent 1638727b7b
commit 36fdc40195
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -75,10 +75,7 @@ let world = `🌍`
let helloWorld = `hello, ${world}`
/* Bindings must be converted to strings */
let age = 10
let ageMsg = `I am ${Js.Int.toString(age)} years old`
/* Using `j` annotation in interpolation will implicitly convert bindings to strings */
let ageMsg = j`I am $age years old`
let ageMsg = `I am ${Int.toString(age)} years old`
/* Concatenate strings with ++ */
@ -169,7 +166,7 @@ let firstTrip = {destination: "London", capacity: 45, averageSpeed: 120.0}
let maxPassengers = firstTrip.capacity
/* If you define the record type in a different file, you have to reference the
filename, if trainJourney was in a file called Trips.re */
filename, if trainJourney was in a file called Trips.res */
let secondTrip: Trips.trainJourney = {
destination: "Paris",
capacity: 50,
@ -306,11 +303,12 @@ let showDialog = (~message: string): unit => {
the `unit` type can also be represented as `()` */
/* > Currying
Functions can be curried and are partially called, allowing for easy reuse */
Functions can be curried and are partially called, allowing for easy reuse
The remaining arguments are represented with ... */
let div = (denom, numr) => numr / denom
let divBySix = div(6)
let divByTwo = div(2)
let divBySix = div(6, ...)
let divByTwo = div(2, ...)
div(3, 24) /* - : int = 8 */
divBySix(128) /* - : int = 21 */
@ -319,7 +317,7 @@ divByTwo(10) /* - : int = 5 */
/* > Optional Labeled Arguments */
/* Use `=?` syntax for optional labeled arguments */
let greetPerson = (~name, ~greeting=?, ()) => {
let greetPerson = (~name, ~greeting=?) => {
switch (greeting) {
| Some(greet) => greet ++ " " ++ name
| None => "Hi " ++ name
@ -330,7 +328,7 @@ let greetPerson = (~name, ~greeting=?, ()) => {
a partial function, to fix this we add `unit` when we declare and call it */
/* Call greetPerson without the optional labeled argument */
greetPerson(~name="Kate", ())
greetPerson(~name="Kate")
/* Call greetPerson with all arguments */
greetPerson(~name="Marco", ~greeting="How are you today,")