expose the optimization to the user in CCBatch

This commit is contained in:
Simon Cruanes 2014-06-11 22:25:59 +02:00
parent 40f8955b34
commit 80522a4959
2 changed files with 19 additions and 0 deletions

View file

@ -45,6 +45,12 @@ module type S = sig
val apply : ('a,'b) op -> 'a t -> 'b t
val apply' : 'a t -> ('a,'b) op -> 'b t
val length : (_,_) op -> int
(** Number of intermediate structures needed to compute this operation *)
val optimize : ('a,'b) op -> ('a,'b) op
(** Try to minimize the length of the operation *)
(** {6 Combinators} *)
val id : ('a, 'a) op
@ -154,6 +160,13 @@ module Make(C : COLLECTION) = struct
| (Compose _) as op ->
Same op (* cannot optimize *)
let rec length : type a b. (a,b) op -> int = function
| Id -> 0
| Compose (_, Id) -> 0
| Compose (_, cont) -> 1 + length cont
let optimize = _optimize
let apply op a =
let rec _apply : type a b. (a,b) op -> a t -> b t
= fun op a -> match op with

View file

@ -51,6 +51,12 @@ module type S = sig
val apply : ('a,'b) op -> 'a t -> 'b t
val apply' : 'a t -> ('a,'b) op -> 'b t
val length : (_,_) op -> int
(** Number of intermediate structures needed to compute this operation *)
val optimize : ('a,'b) op -> ('a,'b) op
(** Try to minimize the length of the operation *)
(** {6 Combinators} *)
val id : ('a, 'a) op