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#115 · main · 21 min 41 s
0Étoiles
0Forks
40Issues
| 1 | // Eq, Ord, Show, Debug, Hash and Default for `()` and tuples (ADR 0018 |
| 2 | // Rev. 1), from the prelude. |
| 3 | |
| 4 | import std/io |
| 5 | |
| 6 | @derive Eq Show Hash |
| 7 | pub type Point { Point(at: (Int, Int), label: String) } |
| 8 | |
| 9 | fn same :: x: a y: a -> Bool where Eq<a> |
| 10 | { |
| 11 | x == y |
| 12 | } |
| 13 | |
| 14 | fn order :: o: Order -> String |
| 15 | { |
| 16 | match o { Lt -> "Lt", Eq -> "Eq", Gt -> "Gt" } |
| 17 | } |
| 18 | |
| 19 | fn smallest :: xs: List<a> best: a -> a where Ord<a> |
| 20 | { |
| 21 | match xs |
| 22 | { [] -> best, [x, ..rest] -> smallest rest if x < best { x } else { best } } |
| 23 | } |
| 24 | |
| 25 | pub fn main :: -> () / <io> |
| 26 | { |
| 27 | io.println (show () <> " " <> debug () <> " " <> show (() == ())) |
| 28 | io.println (show (1, "a") <> " " <> debug (1, "a")) |
| 29 | io.println (show ((1, 2) == (1, 2)) <> " " <> show ((1, 2) == (1, 3))) |
| 30 | io.println (show ((1, "b") < (1, "c")) <> " " <> show ((2, "a") > (1, "z"))) |
| 31 | io.println (show (smallest [(2, "b"), (1, "z"), (2, "a")] (3, ""))) |
| 32 | io.println |
| 33 | ( show (hash (1, 2) == hash (1, 2)) <> " " |
| 34 | <> show (hash (1, 2) == hash (2, 1)) |
| 35 | ) |
| 36 | let zero: (Int, String, Bool) = default () |
| 37 | io.println (debug zero) |
| 38 | io.println |
| 39 | ( show (Point((1, 2), "p") == Point((1, 2), "p")) <> " " |
| 40 | <> show Point((1, 2), "p") |
| 41 | ) |
| 42 | let done: Result<(), String> = Ok(()) |
| 43 | io.println (show (same [("x", 1)] [("x", 1)]) <> " " <> show (done == Ok(()))) |
| 44 | io.println (show (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)) |
| 45 | io.println |
| 46 | ( order |
| 47 | ( compare |
| 48 | (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) |
| 49 | (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13) |
| 50 | ) |
| 51 | ) |
| 52 | } |
| 53 | //> () () True |
| 54 | //> (1, a) (1, "a") |
| 55 | //> True False |
| 56 | //> True True |
| 57 | //> (1, z) |
| 58 | //> True False |
| 59 | //> (0, "", False) |
| 60 | //> True Point((1, 2), p) |
| 61 | //> True True |
| 62 | //> (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) |
| 63 | //> Lt |