aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorGravatar Arnaud Spiwack <arnaud@spiwack.net>2014-10-23 15:42:07 +0200
committerGravatar Arnaud Spiwack <arnaud@spiwack.net>2014-10-23 16:02:45 +0200
commit279ce5a03cb39b6a7fd596e5d339b6f825d03512 (patch)
tree50b20dfde2ca48d938422489027bc5de0e43c3ee /lib
parent4cb05fc1afaf938d1b36e0c00226ff173e2d8f22 (diff)
Monad: change the error managing of two-list combinators.
Otherwise I risked catching errors from the argument functions when I wanted to catch size mismatch to add information to errors.
Diffstat (limited to 'lib')
-rw-r--r--lib/monad.ml16
-rw-r--r--lib/monad.mli13
2 files changed, 9 insertions, 20 deletions
diff --git a/lib/monad.ml b/lib/monad.ml
index bc58c4d17..4a52684da 100644
--- a/lib/monad.ml
+++ b/lib/monad.ml
@@ -67,16 +67,11 @@ module type ListS = sig
(** {6 Two-list iterators} *)
- (** Raised when an combinator expects several lists of the same size
- but finds that they are not. Exceptions must be raised inside
- the monad, so two-list combinators take an extra argument to
- raise the exception. *)
- exception SizeMismatch
-
(** [fold_left2 r f s l1 l2] behaves like {!fold_left} but acts
- simultaneously on two lists. Returns [r SizeMismatch] if both lists
- do not have the same length. *)
- val fold_left2 : (exn->'a t) ->
+ simultaneously on two lists. Runs [r] (presumably an
+ exception-raising computation) if both lists do not have the
+ same length. *)
+ val fold_left2 : 'a t ->
('a -> 'b -> 'c -> 'a t) -> 'a -> 'b list -> 'c list -> 'a t
end
@@ -143,7 +138,6 @@ module Make (M:Def) : S with type +'a t = 'a M.t = struct
| a::b::l -> f a >> f b >> iter f l
- exception SizeMismatch
let rec fold_left2 r f x l1 l2 =
match l1,l2 with
@@ -153,7 +147,7 @@ module Make (M:Def) : S with type +'a t = 'a M.t = struct
f x a1 b1 >>= fun x' ->
f x' a2 b2 >>= fun x'' ->
fold_left2 r f x'' l1 l2
- | _ , _ -> r SizeMismatch
+ | _ , _ -> r
end
diff --git a/lib/monad.mli b/lib/monad.mli
index a6be1df7a..c8655efa0 100644
--- a/lib/monad.mli
+++ b/lib/monad.mli
@@ -69,16 +69,11 @@ module type ListS = sig
(** {6 Two-list iterators} *)
- (** Raised when an combinator expects several lists of the same size
- but finds that they are not. Exceptions must be raised inside
- the monad, so two-list combinators take an extra argument to
- raise the exception. *)
- exception SizeMismatch
-
(** [fold_left2 r f s l1 l2] behaves like {!fold_left} but acts
- simultaneously on two lists. Returns [r SizeMismatch] if both lists
- do not have the same length. *)
- val fold_left2 : (exn->'a t) ->
+ simultaneously on two lists. Runs [r] (presumably an
+ exception-raising computation) if both lists do not have the
+ same length. *)
+ val fold_left2 : 'a t ->
('a -> 'b -> 'c -> 'a t) -> 'a -> 'b list -> 'c list -> 'a t
end