Source file ResultMonad.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
let rec map f =
  function
  | [] -> Ok []
  | x :: xs ->
    Result.bind (f x) @@ fun x ->
    Result.bind (map f xs) @@ fun xs ->
    Ok (x :: xs)

let rec iter f =
  function
  | [] -> Ok ()
  | x :: xs ->
    Result.bind (f x) @@ fun () ->
    Result.bind (iter f xs) @@ fun () ->
    Ok ()