caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Till Varoquaux <till@pps.jussieu.fr>
To: Caml Mailing List <caml-list@yquem.inria.fr>
Subject: Lightweight way to extend existing module. Almost there?
Date: Tue, 16 Nov 2010 23:10:14 -0500	[thread overview]
Message-ID: <AANLkTimZeX-Ntq0NppCpoiDQEc3QomKGDvscMiOk7-hU@mail.gmail.com> (raw)

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


                 reply	other threads:[~2010-11-17  4:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTimZeX-Ntq0NppCpoiDQEc3QomKGDvscMiOk7-hU@mail.gmail.com \
    --to=till@pps.jussieu.fr \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).