Version française
Home     About     Download     Resources     Contact us    
Browse thread
Lightweight way to extend existing module. Almost there?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Till Varoquaux <till@p...>
Subject: Lightweight way to extend existing module. Almost there?
With the improvements to the module system in ocaml 3.12 extending a
signature just got much much lighter. Suppose I want the signature of
the module which in every respects is like StdLabels excepted that the
String module has an extra "is_prefix_of" I can write:

  module String : sig
    include module type of StdLabels.String
    val is_prefix_of : string ->  string ->  bool
  end

  include module type of StdLabels with module String :=  String

I know of no way to extend the implementation in a similarly concise
way (for which the length of the solution does not depend on the
number of top level items in StdLabels). Have I overlooked anything
obvious?

Till

P.S.: FYI existing solution for the implementation:

  module String = struct
    include StringLabels

    let is_prefix_of (needle:string) (haystack:string) : bool =
      let len = length needle in
      len <= length haystack && (sub haystack ~pos:0 ~len = needle)
  end

  (* Haven't quite found out how to include a module hiding another one... *)
  module List = ListLabels
  module Array = ArrayLabels