From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id C267A7F75C for ; Wed, 27 Aug 2014 16:53:03 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of yotambarnoy@gmail.com) identity=pra; client-ip=209.85.216.43; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yotambarnoy@gmail.com"; x-sender="yotambarnoy@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of yotambarnoy@gmail.com designates 209.85.216.43 as permitted sender) identity=mailfrom; client-ip=209.85.216.43; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yotambarnoy@gmail.com"; x-sender="yotambarnoy@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-qa0-f43.google.com) identity=helo; client-ip=209.85.216.43; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yotambarnoy@gmail.com"; x-sender="postmaster@mail-qa0-f43.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkcBAHPv/VPRVdgrlGdsb2JhbABbg2BXBIJ4ySOIXQgWEAEBAQEHCwsJEiuEHBEEGQEbHgMSAwYHNwIkAREBBQEiNYgLAQMRjiGNDoMZa4srgXKDEIkqChknDWaEWBEBBQ6SPoFTAQSVXIZ8jmKEQxgphSshL4JPAQEB X-IPAS-Result: AkcBAHPv/VPRVdgrlGdsb2JhbABbg2BXBIJ4ySOIXQgWEAEBAQEHCwsJEiuEHBEEGQEbHgMSAwYHNwIkAREBBQEiNYgLAQMRjiGNDoMZa4srgXKDEIkqChknDWaEWBEBBQ6SPoFTAQSVXIZ8jmKEQxgphSshL4JPAQEB X-IronPort-AV: E=Sophos;i="5.04,411,1406584800"; d="scan'208";a="76836777" Received: from mail-qa0-f43.google.com ([209.85.216.43]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 27 Aug 2014 16:53:03 +0200 Received: by mail-qa0-f43.google.com with SMTP id w8so313482qac.30 for ; Wed, 27 Aug 2014 07:53:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=jF7xRWAOzDdW9I4pbEVJewr6El5yFjiakqJYwcMgiS8=; b=lyrY6LunE4FkWeEZ2yh+2Yq6z9fPS8k/poEFyz4hXh7A92ITAK8Za0kr7R1CJYkXOV KSJuK86rG4khZ3/wiFsVpHFezMfAyg9SWsvlJ3dw3Cd5Zpu6ZTtWAt9/vZA+SH3lzZJF AMsZg0UNGPUK96s2pyx7gH0l+0xdElJ5WNUsKSqGOHqQPfk7wVZrIwJbKddzSRvVq1Hg EjTkWRCYiWuyBpizP810x94bhnqm8tNVZ+Il8hs43U8GcUcIRqiRdeo/ZW3P6olonhrP pX1SfwwPeE4RFIdh5vOKHkhlh2yr2lTdb+Tx74WygGq9GZX3zGGTDvwFYg4lBkVo3kIb eVvQ== X-Received: by 10.140.50.16 with SMTP id r16mr26417476qga.96.1409151181825; Wed, 27 Aug 2014 07:53:01 -0700 (PDT) MIME-Version: 1.0 Received: by 10.224.210.4 with HTTP; Wed, 27 Aug 2014 07:52:41 -0700 (PDT) From: Yotam Barnoy Date: Wed, 27 Aug 2014 10:52:41 -0400 Message-ID: To: Ocaml Mailing List Content-Type: multipart/alternative; boundary=001a11352804a0b94d05019d9369 Subject: [Caml-list] Problem extending the Standard library --001a11352804a0b94d05019d9369 Content-Type: text/plain; charset=UTF-8 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 --001a11352804a0b94d05019d9369 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
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 =3D
=C2=A0 sig
=C2=A0= =C2=A0 include Map.S
=C2=A0 =C2=A0 val find_lt: key -> 'a= t -> 'a
=C2=A0 =C2=A0 val find_gt: key -> 'a t -&g= t; 'a
=C2=A0 end

module Make(Ord: Map.OrderedType) =3D struct
=C2= =A0 include Map.Make(Ord)

=C2=A0 let find_almost m= ove_f x n =3D=C2=A0
=C2=A0 =C2=A0 let rec loop lastval n =3D
=C2=A0 =C2=A0 =C2=A0 match n, lastval with
=C2=A0 =C2=A0 =C2=A0 | Empty, None =C2=A0 -> raise Not_found
<= div>=C2=A0 =C2=A0 =C2=A0 | Empty, Some i -> i
=C2=A0 =C2=A0 = =C2=A0 | Node(l, v, d, r, _) ->
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 let c =3D Ord.compare x v in
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 let lastval', next =3D move_f c lastval l d r in
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 loop lastval' next
= =C2=A0 in loop None n
=C2=A0=C2=A0
=C2=A0 let move_lt c= lastval l d r =3D
=C2=A0 =C2=A0 if c <=3D 0 then lastval, l e= lse Some d, r

=C2=A0 let move_gt c lastval l d r = =3D
=C2=A0 =C2=A0 if c < 0 =C2=A0then Some d, l else lastval, r

=C2=A0 let find_gt x n =3D find_almost move_gt x n
<= div>=C2=A0 let find_lt x n =3D find_almost move_lt x n
end
<= /div>

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
--001a11352804a0b94d05019d9369--