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.

93 lignes · 1728 octetsBrut · Historique
1// Effect aliases (ADR 0044): a row names a set once; the alias expands
2// to its members, so the type checker sees the same rows as ever.
3
4import std/io
5
6effect log
7{
8 fn log :: msg: String -> ()
9}
10
11effect ask
12{
13 fn ask :: -> Int
14}
15
16effect state<s>
17{
18 fn get :: -> s
19 fn put :: x: s -> ()
20}
21
22effect alias app = log, ask
23
24// An alias expands in a signature's row.
25fn both ::
26{
27 log "hi"
28 let _ = ask ()
29 ()
30}
31//~ TYPE both: fn() -> () / <log, ask>
32
33pub fn declared :: -> () / <app>
34{
35 both ()
36}
37
38// Open rows keep their tail variable.
39pub fn open :: f: fn() -> a / <app | e> -> a / <app | e>
40{
41 f ()
42}
43//~ TYPE open: fn(fn() -> a / <log, ask | e>) -> a / <log, ask | e>
44
45// A member that is itself an alias expands transitively; duplicates
46// collapse.
47effect alias deeper = app, log
48
49pub fn transitively :: -> () / <deeper>
50{
51 both ()
52}
53
54// Applied members expand too.
55effect alias st = state<Int>
56
57pub fn counted ::
58 -> Int / <st> //~ WARN W0501
59{
60 let n = state.get () //~ ERROR E0109
61 state.put (n + 1) //~ ERROR E0109
62 n
63}
64
65// A dead member warns through the alias (W0501; coarser through an
66// alias: it reports the member dead in the alias even where it is live
67// in some other use).
68pub fn half_dead ::
69 -> () / <app> //~ WARN W0501
70{
71 log "yes"
72}
73
74// A bad member ends the alias's row in an error, once, without
75// cascading E0502 at every call (issue #144).
76effect alias unknown = nosucheffect //~ ERROR E0123
77
78pub fn uses_unknown :: -> () / <unknown>
79{
80 io.println "fine"
81}
82
83effect alias selfy = selfy //~ ERROR E0122 refers to itself
84
85effect alias not_effects = Int //~ ERROR E0123
86
87pub fn arity ::
88 -> () / <app<Int>> //~ ERROR E0124 no type arguments
89//~^ WARN W0501
90//~^^ WARN W0501
91{
92 ()
93}