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.

41 lignes · 909 octetsBrut · Historique
1import std/io
2
3// `Wire` (ADR 0072) has a dictionary, unlike `Send`: a function or an
4// impl with `where Wire<a>` takes one, and every caller passes it,
5// derived impls included.
6pub type Box<a> { Box(value: a) }
7
8impl Eq<Box<a>> where Eq<a>, Wire<a>
9{
10 fn eq :: x: Box<a> y: Box<a> -> Bool
11 {
12 match (x, y) { (Box(a), Box(b)) -> a == b }
13 }
14}
15
16// Its field's `Eq` comes from the impl above, which needs `Wire<Int>`.
17@derive Eq
18pub type Labelled { Labelled(String, Box<Int>) }
19
20fn describe :: x: a -> String where Wire<a>, Show<a>
21{
22 show x
23}
24
25// Inferred: `where Wire<a>, Show<a>`.
26fn twice :: x
27{
28 describe [x, x]
29}
30
31pub fn main :: -> () / <io>
32{
33 io.println (show (Labelled("a", Box(1)) == Labelled("a", Box(1))))
34 io.println (show (Labelled("a", Box(1)) == Labelled("a", Box(2))))
35 io.println (describe (1, "two"))
36 io.println (twice True)
37}
38//> True
39//> False
40//> (1, two)
41//> [True, True]