caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Yotam Barnoy <yotambarnoy@gmail.com>
To: Ocaml Mailing List <caml-list@inria.fr>
Subject: [Caml-list] Problem extending the Standard library
Date: Wed, 27 Aug 2014 10:52:41 -0400	[thread overview]
Message-ID: <CAN6ygO=CjGzH3TuWbH9LE2=yYeVErGwDLYZ0xe4Tr0z32ao6Yg@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1055 bytes --]

I've recently tried to extend the Map in the standard library with extra
functionality. This is what I've tried doing:

In a file my_map.ml:

module type S =
  sig
    include Map.S
    val find_lt: key -> 'a t -> 'a
    val find_gt: key -> 'a t -> 'a
  end

module Make(Ord: Map.OrderedType) = struct
  include Map.Make(Ord)

  let find_almost move_f x n =
    let rec loop lastval n =
      match n, lastval with
      | Empty, None   -> raise Not_found
      | Empty, Some i -> i
      | Node(l, v, d, r, _) ->
          let c = Ord.compare x v in
          let lastval', next = move_f c lastval l d r in
          loop lastval' next
  in loop None n

  let move_lt c lastval l d r =
    if c <= 0 then lastval, l else Some d, r

  let move_gt c lastval l d r =
    if c < 0  then Some d, l else lastval, r

  let find_gt x n = find_almost move_gt x n
  let find_lt x n = find_almost move_lt x n
end

Can anyone tell me why the compiler complained about Empty being an unbound
constructor when it's declared in Map.Make, which I include?

Thanks
Yotam

[-- Attachment #2: Type: text/html, Size: 1674 bytes --]

             reply	other threads:[~2014-08-27 14:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-27 14:52 Yotam Barnoy [this message]
2014-08-27 14:59 ` Leo White
2014-08-27 15:01   ` Yotam Barnoy
2014-08-27 15:04 ` Pierrick Couderc

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='CAN6ygO=CjGzH3TuWbH9LE2=yYeVErGwDLYZ0xe4Tr0z32ao6Yg@mail.gmail.com' \
    --to=yotambarnoy@gmail.com \
    --cc=caml-list@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).