mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 19:55:31 -05:00
expose the optimization to the user in CCBatch
This commit is contained in:
parent
40f8955b34
commit
80522a4959
2 changed files with 19 additions and 0 deletions
|
|
@ -45,6 +45,12 @@ module type S = sig
|
||||||
val apply : ('a,'b) op -> 'a t -> 'b t
|
val apply : ('a,'b) op -> 'a t -> 'b t
|
||||||
val apply' : 'a t -> ('a,'b) op -> '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} *)
|
(** {6 Combinators} *)
|
||||||
|
|
||||||
val id : ('a, 'a) op
|
val id : ('a, 'a) op
|
||||||
|
|
@ -154,6 +160,13 @@ module Make(C : COLLECTION) = struct
|
||||||
| (Compose _) as op ->
|
| (Compose _) as op ->
|
||||||
Same op (* cannot optimize *)
|
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 apply op a =
|
||||||
let rec _apply : type a b. (a,b) op -> a t -> b t
|
let rec _apply : type a b. (a,b) op -> a t -> b t
|
||||||
= fun op a -> match op with
|
= fun op a -> match op with
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,12 @@ module type S = sig
|
||||||
val apply : ('a,'b) op -> 'a t -> 'b t
|
val apply : ('a,'b) op -> 'a t -> 'b t
|
||||||
val apply' : 'a t -> ('a,'b) op -> '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} *)
|
(** {6 Combinators} *)
|
||||||
|
|
||||||
val id : ('a, 'a) op
|
val id : ('a, 'a) op
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue