louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#125 · main · 16 min 13 s
0Étoiles
0Forks
40Issues
| 1 | import std/list |
| 2 | |
| 3 | // `multi ctl` operations (ADR 0017): the clause's `resume` may be called |
| 4 | // several times; it is typed like a `ctl` clause's. |
| 5 | |
| 6 | effect amb |
| 7 | { |
| 8 | multi ctl choose :: -> Bool |
| 9 | final ctl fail :: -> Never |
| 10 | } |
| 11 | |
| 12 | pub fn all :: action: fn() -> a / <amb | e> -> List<a> / <e> |
| 13 | { |
| 14 | handle |
| 15 | { |
| 16 | [action ()] |
| 17 | } |
| 18 | with |
| 19 | { choose -> list.append (resume True) (resume False), fail -> [] } |
| 20 | } |
| 21 | //~^^^^^^ TYPE all: fn(fn() -> a / <amb | e>) -> List<a> / <e> |
| 22 | |
| 23 | pub fn bits :: -> List<(Bool, Bool)> |
| 24 | { |
| 25 | all fn { (choose (), choose ()) } |
| 26 | } |
| 27 | |
| 28 | // `resume` takes the operation's result. |
| 29 | pub fn wrong :: -> List<Int> |
| 30 | { |
| 31 | handle |
| 32 | { |
| 33 | [if choose () { 1 } else { 2 }] |
| 34 | } |
| 35 | with |
| 36 | { choose -> resume 1 //~ ERROR E0202 |
| 37 | , fail -> [] |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | // A `final ctl` clause has no `resume`. |
| 42 | pub fn no_resume :: -> List<Int> |
| 43 | { |
| 44 | handle |
| 45 | { |
| 46 | [if choose () { 1 } else { 2 }] |
| 47 | } |
| 48 | with |
| 49 | { choose -> resume True |
| 50 | , fail -> resume True //~ ERROR E0101 resume |
| 51 | } |
| 52 | } |