Skip to content

Commit

Permalink
[rescript/en] update (#4947)
Browse files Browse the repository at this point in the history
  • Loading branch information
yangdanny97 authored May 18, 2024
1 parent 1638727 commit 36fdc40
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions rescript.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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 ++ */
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 */
Expand All @@ -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
Expand All @@ -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,")
Expand Down

0 comments on commit 36fdc40

Please sign in to comment.