Merge branch 'docs/reasonligo-tuple-param' into 'dev'

Change ReasonLIGO and CameLIGO doc examples to use tuple param destructuring

See merge request ligolang/ligo!352
This commit is contained in:
John David Pressman 2020-01-23 06:05:51 +00:00
commit dd47d709bd
7 changed files with 19 additions and 23 deletions

View File

@ -50,8 +50,7 @@ let main (parameter, store: parameter * store) : operation list * store =
```reasonligo group=a ```reasonligo group=a
type parameter = unit; type parameter = unit;
type store = unit; type store = unit;
let main = (parameter_store: (parameter, store)) : (list(operation), store) => { let main = ((parameter, store): (parameter, store)) : (list(operation), store) => {
let parameter, store = parameter_store;
(([]: list(operation)), store); (([]: list(operation)), store);
}; };
``` ```
@ -93,7 +92,7 @@ let main (p, s: unit * unit) : operation list * unit =
<!--ReasonLIGO--> <!--ReasonLIGO-->
```reasonligo group=b ```reasonligo group=b
let main = (p_s: (unit, unit)) : (list(operation), unit) => { let main = ((p,s): (unit, unit)) : (list(operation), unit) => {
if (amount > 0mutez) { if (amount > 0mutez) {
(failwith("This contract does not accept tez"): (list(operation), unit)); (failwith("This contract does not accept tez"): (list(operation), unit));
} }
@ -131,7 +130,7 @@ let main (p,s: unit * unit) : operation list * unit =
<!--ReasonLIGO--> <!--ReasonLIGO-->
```reasonligo group=c ```reasonligo group=c
let owner: address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address); let owner: address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address);
let main = (p_s: (unit, unit)) : (list(operation), unit) => { let main = ((p,s): (unit, unit)) : (list(operation), unit) => {
if (source != owner) { if (source != owner) {
(failwith("This address can't call the contract"): (list(operation), unit)); (failwith("This address can't call the contract"): (list(operation), unit));
} }
@ -230,10 +229,10 @@ type action =
let dest: address = ("KT19wgxcuXG9VH4Af5Tpm1vqEKdaMFpznXT3": address); let dest: address = ("KT19wgxcuXG9VH4Af5Tpm1vqEKdaMFpznXT3": address);
let proxy = (param_s: (action, unit)): (list(operation), unit) => let proxy = ((param, s): (action, unit)): (list(operation), unit) =>
let counter: contract(action) = Operation.get_contract(dest); let counter: contract(action) = Operation.get_contract(dest);
let op: operation = Operation.transaction(param_s[0], 0mutez, counter); let op: operation = Operation.transaction(param, 0mutez, counter);
([op], param_s[1]); ([op], s);
``` ```
<!--END_DOCUSAURUS_CODE_TABS--> <!--END_DOCUSAURUS_CODE_TABS-->

View File

@ -107,8 +107,7 @@ type action =
| Decrement(int) | Decrement(int)
| Reset(unit); | Reset(unit);
let main = (p_s: (action, int)) : (list(operation), int) => { let main = ((p,s): (action, int)) : (list(operation), int) => {
let p, s = p_s;
let result = let result =
switch (p) { switch (p) {
| Increment(n) => s + n | Increment(n) => s + n

View File

@ -74,7 +74,7 @@ Currying is however *not* the preferred way to pass function arguments in CameLI
While this approach is faithful to the original OCaml, it's costlier in Michelson While this approach is faithful to the original OCaml, it's costlier in Michelson
than naive function execution accepting multiple arguments. Instead for most than naive function execution accepting multiple arguments. Instead for most
functions with more than one parameter we should place the arguments in a functions with more than one parameter we should place the arguments in a
[tuple](language-basics/sets-lists-touples.md) and pass the tuple in as a single [tuple](language-basics/sets-lists-tuples.md) and pass the tuple in as a single
parameter. parameter.
Here's how you define a basic function that accepts two `ints` and returns an `int` as well: Here's how you define a basic function that accepts two `ints` and returns an `int` as well:
@ -99,7 +99,7 @@ along with a return type.
Here's how you define a basic function that accepts two `ints` and returns an `int` as well: Here's how you define a basic function that accepts two `ints` and returns an `int` as well:
```reasonligo group=b ```reasonligo group=b
let add = (a: int, b: int) : int => a + b; let add = ((a,b): (int, int)) : int => a + b;
``` ```
The function body is a series of expressions, which are evaluated to give the return The function body is a series of expressions, which are evaluated to give the return

View File

@ -182,14 +182,14 @@ function iter_op (const m : moveset) : unit is
<!--CameLIGO--> <!--CameLIGO-->
```cameligo ```cameligo
let iter_op (m : moveset) : unit = let iter_op (m : moveset) : unit =
let assert_eq = fun (i: address * move) -> assert (i.1.0 > 1) let assert_eq = fun (i,j: address * move) -> assert (j.0 > 1)
in Map.iter assert_eq m in Map.iter assert_eq m
``` ```
<!--ReasonLIGO--> <!--ReasonLIGO-->
```reasonligo ```reasonligo
let iter_op = (m: moveset): unit => { let iter_op = (m: moveset): unit => {
let assert_eq = (i: (address, move)) => assert(i[1][0] > 1); let assert_eq = ((i,j): (address, move)) => assert(j[0] > 1);
Map.iter(assert_eq, m); Map.iter(assert_eq, m);
}; };
``` ```
@ -209,14 +209,14 @@ function map_op (const m : moveset) : moveset is
<!--CameLIGO--> <!--CameLIGO-->
```cameligo ```cameligo
let map_op (m : moveset) : moveset = let map_op (m : moveset) : moveset =
let increment = fun (i: address * move) -> (i.1.0, i.1.1 + 1) let increment = fun (i,j: address * move) -> (j.0, j.1 + 1)
in Map.map increment m in Map.map increment m
``` ```
<!--ReasonLIGO--> <!--ReasonLIGO-->
```reasonligo ```reasonligo
let map_op = (m: moveset): moveset => { let map_op = (m: moveset): moveset => {
let increment = (i: (address, move)) => (i[1][0], i[1][1] + 1); let increment = ((i,j): (address, move)) => (j[0], j[1] + 1);
Map.map(increment, m); Map.map(increment, m);
}; };
``` ```
@ -243,14 +243,14 @@ function fold_op (const m : moveset) : int is
<!--CameLIGO--> <!--CameLIGO-->
```cameligo ```cameligo
let fold_op (m : moveset) : moveset = let fold_op (m : moveset) : moveset =
let aggregate = fun (i: int * (address * (int * int))) -> i.0 + i.1.1.1 in let aggregate = fun (i,j: int * (address * (int * int))) -> i + j.1.1 in
Map.fold aggregate m 5 Map.fold aggregate m 5
``` ```
<!--ReasonLIGO--> <!--ReasonLIGO-->
```reasonligo ```reasonligo
let fold_op = (m: moveset): moveset => { let fold_op = (m: moveset): moveset => {
let aggregate = (i: (int, (address, (int,int)))) => i[0] + i[1][1][1]; let aggregate = ((i,j): (int, (address, (int,int)))) => i + j[1][1];
Map.fold(aggregate, m, 5); Map.fold(aggregate, m, 5);
}; };

View File

@ -257,7 +257,7 @@ let sum_of_a_list: int = List.fold sum my_list 0
<!--ReasonLIGO--> <!--ReasonLIGO-->
```reasonligo group=b ```reasonligo group=b
let sum = (result_i: (int, int)): int => result_i[0] + result_i[1]; let sum = ((result, i): (int, int)): int => result + i;
(* Outputs 6 *) (* Outputs 6 *)
let sum_of_a_list: int = List.fold(sum, my_list, 0); let sum_of_a_list: int = List.fold(sum, my_list, 0);
``` ```

View File

@ -69,8 +69,7 @@ let check_hash_key (kh1, k2: key_hash * key) : bool * key_hash =
<!--ReasonLIGO--> <!--ReasonLIGO-->
```reasonligo ```reasonligo
let check_hash_key = (kh1_k2: (key_hash, key)) : (bool, key_hash) => { let check_hash_key = ((kh1, k2): (key_hash, key)) : (bool, key_hash) => {
let kh1, k2 = kh1_k2;
let kh2 : key_hash = Crypto.hash_key(k2); let kh2 : key_hash = Crypto.hash_key(k2);
if (kh1 == kh2) { if (kh1 == kh2) {
(true, kh2); (true, kh2);
@ -111,8 +110,7 @@ let check_signature (pk, signed, msg: key * signature * bytes) : bool =
<!--ReasonLIGO--> <!--ReasonLIGO-->
```reasonligo ```reasonligo
let check_signature = (param: (key, signature, bytes)) : bool => { let check_signature = ((pk, signed, msg): (key, signature, bytes)) : bool => {
let pk, signed, msg = param;
Crypto.check(pk, signed, msg); Crypto.check(pk, signed, msg);
}; };
``` ```

View File

@ -108,7 +108,7 @@ with a new value being bound in place of the old one.
```reasonligo ```reasonligo
let add = (a: int, b: int): int => { let add = ((a,b): (int, int)): int => {
let c: int = a + b; let c: int = a + b;
c; c;
}; };