tobogganSe connecter

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.

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