blob: 7d3525bcbc724528ca5ca350f46a17a87bfc9c60 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
Explanation: You can ❰merge❱ the alternatives of a union using a record with one
handler per alternative, like this:
┌─────────────────────────────────────────────────────────────────────┐
│ let union = < Left = +2 | Right : Bool > │
│ in let handlers = { Left = Natural/even, Right = λ(x : Bool) → x } │
│ in merge handlers union : Bool │
└─────────────────────────────────────────────────────────────────────┘
... as long as the input type of each handler function matches the type of the
corresponding alternative:
┌───────────────────────────────────────────────────────────┐
│ union : < Left : Natural | Right : Bool > │
└───────────────────────────────────────────────────────────┘
⇧ ⇧
These must match These must match
⇩ ⇩
┌───────────────────────────────────────────────────────────┐
│ handlers : { Left : Natural → Bool, Right : Bool → Bool } │
└───────────────────────────────────────────────────────────┘
For example, the following expression is $_NOT valid:
Invalid: Doesn't match the type of the ❰Right❱ alternative
⇩
┌──────────────────────────────────────────────────────────────────────┐
│ let handlers = { Left = Natural/even | Right = λ(x : Text) → x } │
│ in let union = < Left = +2 | Right : Bool > │
│ in merge handlers union : Bool │
└──────────────────────────────────────────────────────────────────────┘
Your handler for the following alternative:
↳ $txt0
... needs to accept an input value of type:
↳ $txt1
... but actually accepts an input value of a different type:
↳ $txt2
|