mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
[rescript/en] update (#4947)
This commit is contained in:
parent
1638727b7b
commit
36fdc40195
@ -75,10 +75,7 @@ let world = `🌍`
|
|||||||
let helloWorld = `hello, ${world}`
|
let helloWorld = `hello, ${world}`
|
||||||
/* Bindings must be converted to strings */
|
/* Bindings must be converted to strings */
|
||||||
let age = 10
|
let age = 10
|
||||||
let ageMsg = `I am ${Js.Int.toString(age)} years old`
|
let ageMsg = `I am ${Int.toString(age)} years old`
|
||||||
|
|
||||||
/* Using `j` annotation in interpolation will implicitly convert bindings to strings */
|
|
||||||
let ageMsg = j`I am $age years old`
|
|
||||||
|
|
||||||
|
|
||||||
/* Concatenate strings with ++ */
|
/* Concatenate strings with ++ */
|
||||||
@ -169,7 +166,7 @@ let firstTrip = {destination: "London", capacity: 45, averageSpeed: 120.0}
|
|||||||
let maxPassengers = firstTrip.capacity
|
let maxPassengers = firstTrip.capacity
|
||||||
|
|
||||||
/* If you define the record type in a different file, you have to reference the
|
/* 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 = {
|
let secondTrip: Trips.trainJourney = {
|
||||||
destination: "Paris",
|
destination: "Paris",
|
||||||
capacity: 50,
|
capacity: 50,
|
||||||
@ -306,11 +303,12 @@ let showDialog = (~message: string): unit => {
|
|||||||
the `unit` type can also be represented as `()` */
|
the `unit` type can also be represented as `()` */
|
||||||
|
|
||||||
/* > Currying
|
/* > 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 div = (denom, numr) => numr / denom
|
||||||
let divBySix = div(6)
|
let divBySix = div(6, ...)
|
||||||
let divByTwo = div(2)
|
let divByTwo = div(2, ...)
|
||||||
|
|
||||||
div(3, 24) /* - : int = 8 */
|
div(3, 24) /* - : int = 8 */
|
||||||
divBySix(128) /* - : int = 21 */
|
divBySix(128) /* - : int = 21 */
|
||||||
@ -319,7 +317,7 @@ divByTwo(10) /* - : int = 5 */
|
|||||||
/* > Optional Labeled Arguments */
|
/* > Optional Labeled Arguments */
|
||||||
|
|
||||||
/* Use `=?` syntax for optional labeled arguments */
|
/* Use `=?` syntax for optional labeled arguments */
|
||||||
let greetPerson = (~name, ~greeting=?, ()) => {
|
let greetPerson = (~name, ~greeting=?) => {
|
||||||
switch (greeting) {
|
switch (greeting) {
|
||||||
| Some(greet) => greet ++ " " ++ name
|
| Some(greet) => greet ++ " " ++ name
|
||||||
| None => "Hi " ++ 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 */
|
a partial function, to fix this we add `unit` when we declare and call it */
|
||||||
|
|
||||||
/* Call greetPerson without the optional labeled argument */
|
/* Call greetPerson without the optional labeled argument */
|
||||||
greetPerson(~name="Kate", ())
|
greetPerson(~name="Kate")
|
||||||
|
|
||||||
/* Call greetPerson with all arguments */
|
/* Call greetPerson with all arguments */
|
||||||
greetPerson(~name="Marco", ~greeting="How are you today,")
|
greetPerson(~name="Marco", ~greeting="How are you today,")
|
||||||
|
Loading…
Reference in New Issue
Block a user