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 | // Annotated functions are checked against their signature. |
| 2 | |
| 3 | pub fn id :: x: a -> a |
| 4 | { |
| 5 | x |
| 6 | } |
| 7 | //~ TYPE id: fn(a) -> a |
| 8 | |
| 9 | pub fn not_general :: x: a -> a |
| 10 | { |
| 11 | 1 //~ ERROR E0202 expected `a`, found `Int` |
| 12 | } |
| 13 | |
| 14 | pub fn wrong_return :: -> Int |
| 15 | { |
| 16 | "text" //~ ERROR E0202 expected `Int`, found `String` |
| 17 | } |
| 18 | |
| 19 | pub fn needs_constraint :: x: a -> String |
| 20 | { |
| 21 | show x //~ ERROR E0402 `a` is not known to implement `Show` |
| 22 | } |
| 23 | |
| 24 | pub fn has_constraint :: x: a -> String where Show<a> |
| 25 | { |
| 26 | show x |
| 27 | } |
| 28 | |
| 29 | pub fn uses_private :: n: Int -> Int |
| 30 | { |
| 31 | helper n |
| 32 | } |
| 33 | fn helper :: n |
| 34 | { |
| 35 | n * 2 |
| 36 | } |
| 37 | |
| 38 | pub fn bad_arity :: n: Int -> Int |
| 39 | { |
| 40 | helper n n //~ ERROR E0205 too many arguments |
| 41 | } |
| 42 | |
| 43 | pub fn not_callable :: n: Int -> Int |
| 44 | { |
| 45 | n 1 //~ ERROR E0207 not a function |
| 46 | } |
| 47 | |
| 48 | pub fn wrong_type_args :: xs: List<Int, Int> -> Int |
| 49 | //~^ ERROR E0201 takes 1 type argument |
| 50 | { |
| 51 | 0 |
| 52 | } |
| 53 | |
| 54 | pub fn trait_as_type :: |
| 55 | x: Show //~ ERROR E0210 is a trait |
| 56 | -> Int |
| 57 | { |
| 58 | 0 |
| 59 | } |
| 60 | |
| 61 | type Pair<a> = (a, a) |
| 62 | type Loop = Loop //~ ERROR E0208 refers to itself |
| 63 | |
| 64 | pub fn swap :: p: Pair<Int> -> Pair<Int> |
| 65 | { |
| 66 | (p.1, p.0) |
| 67 | } |
| 68 | //~ TYPE swap: fn((Int, Int)) -> (Int, Int) |
| 69 | |
| 70 | fn infinite :: x |
| 71 | { |
| 72 | x x //~ ERROR E0209 infinite |
| 73 | } |
| 74 | |
| 75 | // Labels are declared at the definition (`~b:`); unlabelled arguments |
| 76 | // fill the unlabelled parameters in order, labelled ones apply by name, |
| 77 | // in any order (ADR 0061). |
| 78 | fn both :: a: Int ~b: Int -> Int |
| 79 | { |
| 80 | a - b |
| 81 | } |
| 82 | |
| 83 | pub fn mixed :: -> Int |
| 84 | { |
| 85 | both 1 ~b: 2 + both ~b: 2 1 |
| 86 | } |
| 87 | //~ TYPE mixed: fn() -> Int |
| 88 | |
| 89 | pub fn unlabelled_needs_a_labelled_slot :: -> Int |
| 90 | { |
| 91 | // `b` is labelled: a positional argument cannot fill it. |
| 92 | both 1 2 //~ ERROR E0205 needs its label |
| 93 | } |
| 94 | |
| 95 | pub fn no_such_label :: -> Int |
| 96 | { |
| 97 | both 1 ~nope: 2 //~ ERROR E0204 no parameter or field named `nope` |
| 98 | } |
| 99 | |
| 100 | pub fn too_many_mixed :: -> Int |
| 101 | { |
| 102 | both 1 ~b: 2 3 //~ ERROR E0205 too many arguments |
| 103 | } |