sophia/test/contracts/factorial.aes
Ulf Norell 4d4a14a9ab
GH-196 pattern matching lhs (#210)
* Allow block with separate type signature and definition of a function

For instance,
```
function
  add : (int, int) => int
  add(x, y) = x + y
```

cc #196

* Allow pattern matching in left-hand sides

* Changelog

* Fix type spec

* partial case-on-constructor

* Changelog for pattern-matching lets
2020-01-15 09:41:03 +01:00

18 lines
479 B
Plaintext

// An implementation of the factorial function where each recursive
// call is to another contract. Not the cheapest way to compute factorial.
contract FactorialServer =
entrypoint fac : (int) => int
contract Factorial =
record state = {worker : FactorialServer}
entrypoint init(worker) = {worker = worker}
stateful entrypoint set_worker(worker) = put(state{worker = worker})
entrypoint
fac : int => int
fac(0) = 1
fac(x) = x * state.worker.fac(x - 1)