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.

36 lignes · 785 octetsBrut · Historique
1// Opaque types (ADR 0033): what a module may declare. Their use from other
2// modules (E0117) is tested in crates/louise_types/tests/opaque.rs.
3
4/// Inside its module, an opaque type is like any other.
5@derive Eq Show
6pub opaque type Count { Count(value: Int) }
7
8pub fn count :: n: Int -> Option<Count>
9{
10 if n < 0
11 {
12 None
13 }
14 else
15 {
16 Some(Count(n))
17 }
18}
19
20pub fn value :: c: Count -> Int
21{
22 c.value
23}
24
25pub fn add :: a: Count b: Count -> Count
26{
27 match a { Count(n) -> Count(..b, value: n + b.value) }
28}
29
30opaque type Secret { Secret(Int) } //~ ERROR E0118 already private
31pub opaque type Meters = Int //~ ERROR E0118 an alias
32pub opaque type Handle //~ ERROR E0118 abstract type
33
34@derive Default
35pub opaque type Total //~ ERROR E0408 opaque type `Total`
36{ Total(Int) }