package alba

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file result.ml

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
66
67
68
69
70
71
72
73
74
75
76
77
78
open Module_types



type ('a, 'e) t = ('a, 'e) result


let (>>=)
    (m: ('a, 'e) t)
    (f: 'a -> ('b, 'e) t)
    : ('b, 'e) t
    =
    match m with
    | Ok a ->
        f a
    | Error e ->
        Error e



let map (f: 'a -> 'b) (m: ('a, 'e) t): ('b, 'e) t =
    match m with
    | Ok a ->
        Ok (f a)
    | Error e ->
        Error e



let map_error (f: 'e1 -> 'e2) (m: ('a,'e1) t): ('a, 'e2) t =
    match m with
    | Ok a ->
        Ok a
    | Error e ->
        Error (f e)


let throw (e: 'e): ('a, 'e) t =
    Error e


let catch (m: ('a, 'e) t) (f: 'e -> ('a, 'e) t): ('a, 'e) t =
    match m with
    | Ok a ->
        Ok a
    | Error e ->
        f e




module Make (Error: ANY) =
struct
    type error = Error.t

    include
        Monad.Of_sig_min (
            struct
                type 'a t = ('a, error) result

                let return (a: 'a): 'a t =
                    Ok a

                let (>>=) = (>>=)
            end
        )

    let throw = throw

    let catch = catch

    let continue m f g =
        match m with
        | Ok a ->
            f a
        | Error e ->
            g e
end
OCaml

Innovation. Community. Security.