ligo/src/test/contracts/match.mligo

36 lines
632 B
Plaintext
Raw Normal View History

type storage = int
type param =
Add of int
| Sub of int
let%entry main (p : param) storage =
let storage =
storage +
(match p with
Add n -> n
| Sub n -> 0-n)
in (([] : operation list), storage)
2019-10-29 08:38:29 +04:00
let match_list (l: int list) : int =
match l with
hd :: tl -> hd
| [] -> 10
(* TODO: Add support for matching options
type option_param =
Add of int option
| Sub of int option
let match_option (p : option_param) storage =
let storage =
storage +
(match p with
Some (Add n) -> n
| Some (Sub n) -> 0 - n
| None -> 0)
in (([] : operation list) , storage)
*)