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 | import std/io |
| 2 | |
| 3 | // `Wire` (ADR 0072) has a dictionary, unlike `Send`: a function or an |
| 4 | // impl with `where Wire<a>` takes one, and every caller passes it, |
| 5 | // derived impls included. |
| 6 | pub type Box<a> { Box(value: a) } |
| 7 | |
| 8 | impl Eq<Box<a>> where Eq<a>, Wire<a> |
| 9 | { |
| 10 | fn eq :: x: Box<a> y: Box<a> -> Bool |
| 11 | { |
| 12 | match (x, y) { (Box(a), Box(b)) -> a == b } |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | // Its field's `Eq` comes from the impl above, which needs `Wire<Int>`. |
| 17 | @derive Eq |
| 18 | pub type Labelled { Labelled(String, Box<Int>) } |
| 19 | |
| 20 | fn describe :: x: a -> String where Wire<a>, Show<a> |
| 21 | { |
| 22 | show x |
| 23 | } |
| 24 | |
| 25 | // Inferred: `where Wire<a>, Show<a>`. |
| 26 | fn twice :: x |
| 27 | { |
| 28 | describe [x, x] |
| 29 | } |
| 30 | |
| 31 | pub fn main :: -> () / <io> |
| 32 | { |
| 33 | io.println (show (Labelled("a", Box(1)) == Labelled("a", Box(1)))) |
| 34 | io.println (show (Labelled("a", Box(1)) == Labelled("a", Box(2)))) |
| 35 | io.println (describe (1, "two")) |
| 36 | io.println (twice True) |
| 37 | } |
| 38 | //> True |
| 39 | //> False |
| 40 | //> (1, two) |
| 41 | //> [True, True] |