summaryrefslogtreecommitdiff
path: root/examples/maybe.sin
blob: 91367cd56bf9626e678d7818aa3a9ab715803b01 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[type just_ [kind val]]
[type none_ [kind]]

[def just [val]
    [just_ 1 val]]

[def just.val [x]
    [just_.val x]]

[def none []
    [none_ 0]]

[def has_value [x]
    [just_.kind x]]

[def Maybe.>>= [a f]
    [if [has_value a]
        [f [just.val a]]
        a]]

[def Maybe.return [x]
    [just x]]