diff options
author | Danny Yang <yangdanny97@users.noreply.github.com> | 2024-05-18 11:20:04 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-18 09:20:04 -0600 |
commit | 36fdc4019569358b0039c86029336b14ad9e9769 (patch) | |
tree | e5089848123f993b04511436b09a915d03c2031a /rescript.html.markdown | |
parent | 1638727b7b1a72e357f4046fd8903de6eec4cfcf (diff) |
[rescript/en] update (#4947)
Diffstat (limited to 'rescript.html.markdown')
-rw-r--r-- | rescript.html.markdown | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/rescript.html.markdown b/rescript.html.markdown index b633332c..4839631a 100644 --- a/rescript.html.markdown +++ b/rescript.html.markdown @@ -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,") |