+ let success_closure ks k =
+ (fun matched_terms terms ->
+ match ks matched_terms with
+ None ->
+ begin
+ (* the match has failed, we rollback the last matched term
+ * into the unmatched ones and call the failure continuation
+ *)
+ match matched_terms with
+ hd :: tl -> k tl (hd :: terms)
+ | _ -> assert false
+ end
+ | Some v -> Some v)
+