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 | // 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 | |
| 4 | import std/io |
| 5 | |
| 6 | effect log |
| 7 | { |
| 8 | fn log :: msg: String -> () |
| 9 | } |
| 10 | |
| 11 | effect ask |
| 12 | { |
| 13 | fn ask :: -> Int |
| 14 | } |
| 15 | |
| 16 | effect state<s> |
| 17 | { |
| 18 | fn get :: -> s |
| 19 | fn put :: x: s -> () |
| 20 | } |
| 21 | |
| 22 | effect alias app = log, ask |
| 23 | |
| 24 | // An alias expands in a signature's row. |
| 25 | fn both :: |
| 26 | { |
| 27 | log "hi" |
| 28 | let _ = ask () |
| 29 | () |
| 30 | } |
| 31 | //~ TYPE both: fn() -> () / <log, ask> |
| 32 | |
| 33 | pub fn declared :: -> () / <app> |
| 34 | { |
| 35 | both () |
| 36 | } |
| 37 | |
| 38 | // Open rows keep their tail variable. |
| 39 | pub 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. |
| 47 | effect alias deeper = app, log |
| 48 | |
| 49 | pub fn transitively :: -> () / <deeper> |
| 50 | { |
| 51 | both () |
| 52 | } |
| 53 | |
| 54 | // Applied members expand too. |
| 55 | effect alias st = state<Int> |
| 56 | |
| 57 | pub 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). |
| 68 | pub 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). |
| 76 | effect alias unknown = nosucheffect //~ ERROR E0123 |
| 77 | |
| 78 | pub fn uses_unknown :: -> () / <unknown> |
| 79 | { |
| 80 | io.println "fine" |
| 81 | } |
| 82 | |
| 83 | effect alias selfy = selfy //~ ERROR E0122 refers to itself |
| 84 | |
| 85 | effect alias not_effects = Int //~ ERROR E0123 |
| 86 | |
| 87 | pub fn arity :: |
| 88 | -> () / <app<Int>> //~ ERROR E0124 no type arguments |
| 89 | //~^ WARN W0501 |
| 90 | //~^^ WARN W0501 |
| 91 | { |
| 92 | () |
| 93 | } |