-
Notifications
You must be signed in to change notification settings - Fork 0
/
maybe.dats
36 lines (25 loc) · 851 Bytes
/
maybe.dats
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
#define ATS_DYNLOADFLAG 0
#include "share/atspre_staload.hats"
staload "./maybe.sats"
(******************************)
staload "./order.sats"
staload _ = "./order.dats"
implement (a) order_compare<maybe a> (x, y) =
case+ (x, y) of
| (Nothing _, Nothing _) => 0
| (Just x, Just y) => order_compare<a> (x, y)
| (Nothing _, _) => ~1
| (_, Nothing _) => 1
(******************************)
staload "./show.sats"
staload _ = "./show.dats"
implement (a) show_any<maybe a> (m) =
case+ m of
| Just x => ignoret (show_any<string> "Just ("; show_any<a> x; show_any<string> ")")
| Nothing () => ignoret (show_any<string> "Nothing")
(******************************)
implement {a,b} maybe_bind (m, f) =
case+ m of
| Nothing _ => Nothing ()
| Just (x) => Just (f x)
(******************************)