Source

planck / lib / smemo.mli

Full commit
(** Stream module extention for memoization 

    This module is very preliminary.
*)

type memo (** Abstract type for memoization table *)
val create : unit -> memo (** Create an empty memo table *)

module type X = sig
  type stream
  module Memo : sig
    type 'a t  (* abstract memoized function *)
    val register : (stream -> 'a) -> 'a t
    val call : 'a t -> stream -> 'a
  end
end

module type S = sig
  include Stream_intf.S
  include X with type stream := t
end                            

module Extend(Base : sig
  include Stream_intf.S
  val memo : Attr.t -> memo
  (** Each attribute of stream element must have a [memo] table, 
      which must be created by [create ()].

      Note that each stream element must have independent [memo] value.
      Sharing memo tables between stream elements causes unexpected result
      at [Memo.call].
  *)
end) : X with type stream := Base.t

(*
module Make(Base : sig
  include Stream_intf.S
  val memo : Attr.t -> memo
end) : S with type desc   = Base.desc
         and  type Elem.t = Base.Elem.t
         and  type Pos.t  = Base.Pos.t
         and  type Attr.t = Base.Attr.t
*)