tobogganSe connecter

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.

52 lignes · 945 octetsBrut · Historique
1import 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
6effect amb
7{
8 multi ctl choose :: -> Bool
9 final ctl fail :: -> Never
10}
11
12pub 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
23pub fn bits :: -> List<(Bool, Bool)>
24{
25 all fn { (choose (), choose ()) }
26}
27
28// `resume` takes the operation's result.
29pub 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`.
42pub 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}