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 | // 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 |
| 6 | pub opaque type Count { Count(value: Int) } |
| 7 | |
| 8 | pub 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 | |
| 20 | pub fn value :: c: Count -> Int |
| 21 | { |
| 22 | c.value |
| 23 | } |
| 24 | |
| 25 | pub fn add :: a: Count b: Count -> Count |
| 26 | { |
| 27 | match a { Count(n) -> Count(..b, value: n + b.value) } |
| 28 | } |
| 29 | |
| 30 | opaque type Secret { Secret(Int) } //~ ERROR E0118 already private |
| 31 | pub opaque type Meters = Int //~ ERROR E0118 an alias |
| 32 | pub opaque type Handle //~ ERROR E0118 abstract type |
| 33 | |
| 34 | @derive Default |
| 35 | pub opaque type Total //~ ERROR E0408 opaque type `Total` |
| 36 | { Total(Int) } |