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 | // Row evidence (ADR 0066, issue #361): a call type-checks whatever the order |
| 2 | // of its arguments. `e` is known from `app` only, directly or inside a |
| 3 | // lambda; the lambda that calls `render` inside a handler may come first. |
| 4 | |
| 5 | import std/io |
| 6 | |
| 7 | effect ask |
| 8 | { |
| 9 | fn ask :: -> Int |
| 10 | } |
| 11 | |
| 12 | effect async<e> |
| 13 | { |
| 14 | fn later :: render: send fn() -> Int / <e> -> Int |
| 15 | } |
| 16 | |
| 17 | fn with_ask :: n: Int action: fn() -> a / <ask | e> -> a / <e> |
| 18 | { |
| 19 | handle |
| 20 | { |
| 21 | action () |
| 22 | } |
| 23 | with |
| 24 | { ask -> n } |
| 25 | } |
| 26 | |
| 27 | fn run_with :: |
| 28 | within: fn(fn() -> Int / <e>) -> Int |
| 29 | action: fn() -> a / <async<e> | e2> |
| 30 | -> a / <e2> |
| 31 | { |
| 32 | handle |
| 33 | { |
| 34 | action () |
| 35 | } |
| 36 | with |
| 37 | { later render -> within render } |
| 38 | } |
| 39 | |
| 40 | fn run_after :: |
| 41 | action: fn() -> a / <async<e> | e2> |
| 42 | within: fn(fn() -> Int / <e>) -> Int |
| 43 | -> a / <e2> |
| 44 | { |
| 45 | handle |
| 46 | { |
| 47 | action () |
| 48 | } |
| 49 | with |
| 50 | { later render -> within render } |
| 51 | } |
| 52 | |
| 53 | fn app :: -> Int / <async<<ask>>> |
| 54 | { |
| 55 | later fn { ask () + 1 } |
| 56 | } |
| 57 | |
| 58 | pub fn main :: -> () / <io> |
| 59 | { |
| 60 | io.println "{run_after app fn render { with_ask 41 fn { render () } }}" |
| 61 | io.println "{run_with (fn render { with_ask 41 fn { render () } }) app}" |
| 62 | io.println |
| 63 | "{run_with (fn render { with_ask 1 fn { render () } }) fn { app () }}" |
| 64 | } |
| 65 | //> 42 |
| 66 | //> 42 |
| 67 | //> 2 |