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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id B16327F75C for ; Wed, 27 Aug 2014 17:04:16 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of pierrickcouderc@gmail.com) identity=pra; client-ip=209.85.216.47; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="pierrickcouderc@gmail.com"; x-sender="pierrickcouderc@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of pierrickcouderc@gmail.com designates 209.85.216.47 as permitted sender) identity=mailfrom; client-ip=209.85.216.47; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="pierrickcouderc@gmail.com"; x-sender="pierrickcouderc@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-qa0-f47.google.com) identity=helo; client-ip=209.85.216.47; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="pierrickcouderc@gmail.com"; x-sender="postmaster@mail-qa0-f47.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkgBAC3z/VPRVdgvlGdsb2JhbABbg2BNCgSCeMkjh1QBgQgIFhABAQEBBwsLCRIrhAQBAQMBEhEEGQEbHQEDAQsGAwIEBzcCAiEBAREBBQEcBhMiiAsBAwkIjhmQJ2uLK4FygxCJKgoZJw1mhFgRAQUOjRGCLQeCeYFTAQSVXIRsghCOYIRFGCmFETsvgk8BAQE X-IPAS-Result: AkgBAC3z/VPRVdgvlGdsb2JhbABbg2BNCgSCeMkjh1QBgQgIFhABAQEBBwsLCRIrhAQBAQMBEhEEGQEbHQEDAQsGAwIEBzcCAiEBAREBBQEcBhMiiAsBAwkIjhmQJ2uLK4FygxCJKgoZJw1mhFgRAQUOjRGCLQeCeYFTAQSVXIRsghCOYIRFGCmFETsvgk8BAQE X-IronPort-AV: E=Sophos;i="5.04,411,1406584800"; d="scan'208";a="91712673" Received: from mail-qa0-f47.google.com ([209.85.216.47]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 27 Aug 2014 17:04:15 +0200 Received: by mail-qa0-f47.google.com with SMTP id i13so332911qae.6 for ; Wed, 27 Aug 2014 08:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=hCitqLTqRVkdcVNUhBsM0xv2I0qu0EVL+NeZLKfABY4=; b=hELHu2Tn//bGWarcd4K3qomK9MeEhx/ZxG7jPoeSc1W9wNUSX5N36f9fBf/2OfsMpd qQOzLtVORAqADYtftEV9OJgsPs1Six83bpd3A2aGKhKbD9x0U/xvn8lSElx1WS9Rmk7l LZ7yGIiAfAVEr3WTrVX+5cWqnlfikxsgcftAy2Qbgh3GqBd0cRyu6WY2tj/oTMpQ+y8M AvcJLolBuG/biWhDk6/njsn2Gc8Ne/pM7iQ8yd6W/vByS397RgHaz49lgEyoirikRzUN 01Zcr2dG7D0ZHmBPAE3Aw73YQyeVUweWc6sstQVvsJHQrivgJFXPKhvnoI2w4bHigAzk xI7A== MIME-Version: 1.0 X-Received: by 10.140.51.81 with SMTP id t75mr35926784qga.37.1409151854770; Wed, 27 Aug 2014 08:04:14 -0700 (PDT) Received: by 10.224.5.6 with HTTP; Wed, 27 Aug 2014 08:04:14 -0700 (PDT) Received: by 10.224.5.6 with HTTP; Wed, 27 Aug 2014 08:04:14 -0700 (PDT) In-Reply-To: References: Date: Wed, 27 Aug 2014 17:04:14 +0200 Message-ID: From: Pierrick Couderc To: Yotam Barnoy Cc: Ocaml Mailing List Content-Type: multipart/alternative; boundary=001a11354a8ebd088405019dbbe4 Subject: Re: [Caml-list] Problem extending the Standard library --001a11354a8ebd088405019dbbe4 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Actually, the type of "+'a t" is not exported in Map.S, therefore it cannot be used directly, even when including the module (or I am mistaking the include semantics). Le 27 ao=C3=BBt 2014 16:54, "Yotam Barnoy" a =C3=A9= crit : > 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 > sig > include Map.S > val find_lt: key -> 'a t -> 'a > val find_gt: key -> 'a t -> 'a > end > > module Make(Ord: Map.OrderedType) =3D struct > include Map.Make(Ord) > > let find_almost move_f x n =3D > let rec loop lastval n =3D > match n, lastval with > | Empty, None -> raise Not_found > | Empty, Some i -> i > | Node(l, v, d, r, _) -> > let c =3D Ord.compare x v in > let lastval', next =3D move_f c lastval l d r in > loop lastval' next > in loop None n > > let move_lt c lastval l d r =3D > if c <=3D 0 then lastval, l else Some d, r > > let move_gt c lastval l d r =3D > if c < 0 then Some d, l else lastval, r > > let find_gt x n =3D find_almost move_gt x n > let find_lt x n =3D 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 > --001a11354a8ebd088405019dbbe4 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

Actually, the type of "+'a t" is not exported = in Map.S, therefore it cannot be used directly, even when including the mod= ule (or I am mistaking the include semantics).=C2=A0

Le 27 ao=C3=BBt 2014 16:54, "Yotam Barnoy&q= uot; <yotambarnoy@gmail.com= > a =C3=A9crit :
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_ma= p.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
--001a11354a8ebd088405019dbbe4--