
louise
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#1201 · main · 9 min 57 s
1Étoiles
0Forks
0Issues
| 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 | |
| 4 | import std/result |
| 5 | |
| 6 | type Msg { Peek(reply: Int), Pair(a: Int, b: String) } |
| 7 | |
| 8 | fn apply :: f: fn(Int) -> Msg x: Int -> Msg |
| 9 | { |
| 10 | f x |
| 11 | } |
| 12 | |
| 13 | pub fn passed :: -> Msg |
| 14 | { |
| 15 | apply Peek 1 |
| 16 | } |
| 17 | |
| 18 | pub fn stored :: -> Msg |
| 19 | { |
| 20 | let f = Peek |
| 21 | f 1 |
| 22 | } |
| 23 | |
| 24 | pub fn mapped :: r: Result<Int, String> -> Result<Msg, String> |
| 25 | { |
| 26 | result.map r Peek |
| 27 | } |
| 28 | |
| 29 | pub 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. |
| 36 | pub fn labelled :: -> Msg |
| 37 | { |
| 38 | let f = Peek |
| 39 | f ~reply: 1 //~ ERROR E0204 |
| 40 | } |
| 41 | |
| 42 | // Construction keeps its labelled fields. |
| 43 | pub fn constructed :: -> Msg |
| 44 | { |
| 45 | Pair(b: "two", a: 2) |
| 46 | } |