-
Notifications
You must be signed in to change notification settings - Fork 0
/
MLS.Result.fst
65 lines (56 loc) · 1.47 KB
/
MLS.Result.fst
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module MLS.Result
#set-options "--fuel 0 --ifuel 0"
type result (a:Type) =
| Success: v:a -> result a
| InternalError: string -> result a
| ProtocolError: string -> result a
val return: #a:Type -> a -> result a
let return #a x = Success x
val internal_failure: #a:Type -> s:string -> result a
let internal_failure #a s = InternalError s
val error: #a:Type -> s:string -> result a
let error #a s = ProtocolError s
#push-options "--ifuel 1"
val (let?):
#a:Type -> #b:Type ->
result a -> (a -> result b) ->
result b
let (let?) #a #b rx f =
match rx with
| Success x -> f x
| InternalError x -> InternalError x
| ProtocolError x -> ProtocolError x
#pop-options
val from_option:
#a:Type ->
string -> option a ->
result a
let from_option #a s x =
match x with
| None -> error s
| Some x -> return x
#push-options "--ifuel 1 --fuel 1"
val mapM:
#a:Type -> #b:Type ->
(a -> result b) -> l:list a ->
result (res:list b{List.Tot.length res == List.Tot.length l})
let rec mapM #a #b f l =
match l with
| [] -> return []
| h::t ->
let? fh = f h in
let? ft = mapM f t in
return #(res:list b{List.Tot.length res == List.Tot.length l}) (fh::ft)
#pop-options
#push-options "--ifuel 1 --fuel 1"
val fold_leftM:
#a:Type -> #b:Type ->
(a -> b -> result a) -> a -> list b ->
result a
let rec fold_leftM #a #b f x l: Tot (result a) (decreases l) =
match l with
| [] -> return x
| h::t ->
let? new_x = f x h in
fold_leftM f new_x t
#pop-options