diff --git a/data/tutorials/language/0lg_10_polymorphic_variants.md b/data/tutorials/language/0lg_10_polymorphic_variants.md index 1b70436a37..35830cfbe6 100644 --- a/data/tutorials/language/0lg_10_polymorphic_variants.md +++ b/data/tutorials/language/0lg_10_polymorphic_variants.md @@ -510,7 +510,7 @@ Let's consider this exception-raising code: val f_exn : int -> int -> int = ``` -The following is an attempt at translating `f_exn` with `result` values instead of exceptions. It is using the `Result.bind` instead of `|>`: +The following is an attempt at translating `f_exn` with `result` values instead of exceptions. It is using `Result.bind` as a [binding operator](docs/operators#binding-operators) instead of `|>`: ```ocaml # type init_error = Negative_length;; @@ -526,6 +526,10 @@ type nth_error = Too_short of int * int | Negative_index of int | Failure _ -> Error (Too_short (List.length u, i)) val nth : 'a list -> int -> ('a, nth_error) result = +# let ( let* ) = Result.bind;; +val ( let* ) : ('a, 'b) result -> ('a -> ('c, 'b) result) -> ('c, 'b) result = + + # let f_res m n = let* u = init m Fun.id in let u = List.map (fun n -> n * n) u in @@ -545,10 +549,6 @@ Binding can't change the `'e` type, while this code needs it to change throughou Here is an equivalent version using polymorphic variants: ```ocaml -# let ( let* ) = Result.bind;; -val ( let* ) : ('a, 'b) result -> ('a -> ('c, 'b) result) -> ('c, 'b) result = - - # let init n f = try Ok (List.init n f) with | Invalid_argument _ -> Error `Negative_length;; val init : int -> (int -> 'a) -> ('a list, [> `Negative_length ]) result =