tobogganSe connecter

louise

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

46 lignes · 736 octetsBrut · Historique
1// A constructor used as a value is a function of its fields, by position:
2// its field names are not parameter labels (ADR 0062, issue #320).
3
4import std/result
5
6type Msg { Peek(reply: Int), Pair(a: Int, b: String) }
7
8fn apply :: f: fn(Int) -> Msg x: Int -> Msg
9{
10 f x
11}
12
13pub fn passed :: -> Msg
14{
15 apply Peek 1
16}
17
18pub fn stored :: -> Msg
19{
20 let f = Peek
21 f 1
22}
23
24pub fn mapped :: r: Result<Int, String> -> Result<Msg, String>
25{
26 result.map r Peek
27}
28
29pub fn two_fields :: -> Msg
30{
31 let f = Pair
32 f 1 "one"
33}
34
35// A field name is not a label of the value.
36pub fn labelled :: -> Msg
37{
38 let f = Peek
39 f ~reply: 1 //~ ERROR E0204
40}
41
42// Construction keeps its labelled fields.
43pub fn constructed :: -> Msg
44{
45 Pair(b: "two", a: 2)
46}