ligo/src/test/contracts/list.religo

34 lines
785 B
Plaintext
Raw Normal View History

2020-03-02 18:01:56 +01:00
type storage = (int, list (int));
2019-12-10 13:47:31 +00:00
2020-03-02 18:01:56 +01:00
type parameter = list (int);
2019-12-10 13:47:31 +00:00
2020-03-02 18:01:56 +01:00
type return = (list (operation), storage);
2019-12-10 13:47:31 +00:00
2020-03-02 18:01:56 +01:00
let x : list (int) = [];
let y : list (int) = [3, 4, 5];
let z : list (int) = [2, ...y];
let main = ((action, s) : (parameter, storage)) : return => {
2019-12-10 13:47:31 +00:00
let storage =
switch (action) {
2020-03-02 18:01:56 +01:00
| [] => s
| [hd, ...tl] => (s[0] + hd, tl)
2019-12-10 13:47:31 +00:00
};
([]: list(operation), storage);
};
2020-03-02 18:01:56 +01:00
let size_ = (s : list (int)) : nat => List.length (s);
2020-03-02 18:01:56 +01:00
let fold_op = (s : list (int)) : int => {
let aggregate = (t: (int, int)) => t[0] + t[1];
List.fold (aggregate, s, 10);
2019-12-10 13:47:31 +00:00
};
2020-03-02 18:01:56 +01:00
let map_op = (s : list (int)) : list (int) =>
List.map ((cur : int) => cur + 1, s);
2019-12-10 13:47:31 +00:00
2020-03-02 18:01:56 +01:00
let iter_op = (s : list (int)) : unit => {
let do_nothing = (useless : int) => unit;
List.iter (do_nothing, s);
2019-12-10 13:47:31 +00:00
};