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 | // A name must denote the kind of thing its position needs. |
| 2 | |
| 3 | import std/io |
| 4 | |
| 5 | type Shape { Circle(Int), Square(Int) } |
| 6 | |
| 7 | effect log |
| 8 | { |
| 9 | fn log :: msg: String -> () |
| 10 | } |
| 11 | |
| 12 | fn area :: s: Shape -> Int |
| 13 | { |
| 14 | match s { Circle(r) -> 3 * r * r, Square(side) -> side * side } |
| 15 | } |
| 16 | |
| 17 | // A module, a type or a function where a value or constructor is needed |
| 18 | // (E0109). |
| 19 | fn module_as_value :: |
| 20 | { |
| 21 | let printer = io //~ ERROR E0109 `io` is a module, not a value |
| 22 | } |
| 23 | |
| 24 | fn type_as_value :: |
| 25 | { |
| 26 | let s = Shape //~ ERROR E0109 `Shape` is a type, trait or effect, not a value |
| 27 | } |
| 28 | |
| 29 | fn function_as_pattern :: s: Shape -> Int |
| 30 | { |
| 31 | match s |
| 32 | { io.println(x) -> 0 //~ ERROR E0109 `io.println` is not a constructor |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | // A handler clause names an operation (E0112). |
| 37 | fn handles_a_function :: -> () |
| 38 | { |
| 39 | handle |
| 40 | { |
| 41 | log "hi" |
| 42 | } |
| 43 | with |
| 44 | { log m -> () |
| 45 | , area s -> () //~ ERROR E0112 `area` is not an effect operation |
| 46 | } |
| 47 | } |