Permalink
Browse files

Add some combinators to ease isolating effects

  • Loading branch information...
let-def committed Feb 10, 2013
1 parent 45b044b commit ec9043872383a5f998d340ce9824bf0b746d6972
Showing with 12 additions and 0 deletions.
  1. +8 −0 utils/misc.ml
  2. +4 −0 utils/misc.mli
View
@@ -338,6 +338,14 @@ let sum f g = function
| Inl a -> f a
| Inr b -> g b
+let sum_join = function
+ | Inl a | Inr (Inl a) -> Inl a
+ | Inr c -> c
+
+let catch_join (exns, r) = match r with
+ | Inl e -> (exns, Inl e)
+ | Inr (exns', r') -> (exns @ exns'), r'
+
(* Manipulating Lexing.position *)
let make_pos (pos_lnum, pos_cnum) =
View
@@ -162,6 +162,10 @@ val list_drop_while : ('a -> bool) -> 'a list -> 'a list
(* Usual either/sum type *)
type ('a,'b) sum = Inl of 'a | Inr of 'b
val sum : ('a -> 'c) -> ('b -> 'c) -> ('a,'b) sum -> 'c
+val sum_join : ('a,('a,'c) sum) sum -> ('a,'c) sum
+
+ (* Join for catch pattern (writer and error monad) *)
+val catch_join : 'a list * ('a, 'a list * ('a, 'b) sum) sum -> 'a list * ('a, 'b) sum
(* Manipulating Lexing.position *)
val make_pos : int * int -> Lexing.position

0 comments on commit ec90438

Please sign in to comment.