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 B98F97FACB for ; Fri, 5 Sep 2014 04:41:49 +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.192.53; 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.192.53 as permitted sender) identity=mailfrom; client-ip=209.85.192.53; 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-qg0-f53.google.com) identity=helo; client-ip=209.85.192.53; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yotambarnoy@gmail.com"; x-sender="postmaster@mail-qg0-f53.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApYBAJshCVTRVcA1m2dsb2JhbABag2BXBIJ4xTiHTAGBAQgWEAEBAQEBBgsLCRQphAMBAQEDARIRBBkBGx4DAQsGBQsNKgICIQEBEQEFARwGEwgTB4gLAQMJCA2bZWuLK4FygxCJIwoZJw1mhXQBEQEBBA6NEoIpC4J5gVMBBI8phkWEboIQjmqERhgphS4hL4JPAQEB X-IPAS-Result: ApYBAJshCVTRVcA1m2dsb2JhbABag2BXBIJ4xTiHTAGBAQgWEAEBAQEBBgsLCRQphAMBAQEDARIRBBkBGx4DAQsGBQsNKgICIQEBEQEFARwGEwgTB4gLAQMJCA2bZWuLK4FygxCJIwoZJw1mhXQBEQEBBA6NEoIpC4J5gVMBBI8phkWEboIQjmqERhgphS4hL4JPAQEB X-IronPort-AV: E=Sophos;i="5.04,470,1406584800"; d="scan'208";a="77819172" Received: from mail-qg0-f53.google.com ([209.85.192.53]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 05 Sep 2014 04:41:48 +0200 Received: by mail-qg0-f53.google.com with SMTP id z107so10879207qgd.26 for ; Thu, 04 Sep 2014 19:41:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=PdMeETvIP7E3rVh9BgLtuhPuPbuHAqx2jMAbOlbVuW0=; b=Rv5EUTGEVF1p4uAUojN8ITJmek55nVL5habCJtw86+mFciGiW5sUFAb67Py9iTdkNk 2yMeB3ONtWpP+7uNiMun5KbgHXsupOfAIbkcxJO1lPoBz7vW8pa0/IvmSykwiO0DMo6t LbifQNevNksd3v+2qAE1730hgzmKH7B++cAEEQUo8NghIwsXSuSjJhLOTugiWCfpRLWt Svcg0eIjMzHcduNC/PiYM7yH+PppOc9AvXiXmUbXX0jr04LDFgPcqyqtzPT3h4pvEpBO HWy0fGwakN65xEHdmd6CUSG25WCg+WX5qEthapC+Vy3jETVfQQ0vBUy3zuzf6SB6ZxI5 2Z5A== X-Received: by 10.140.30.74 with SMTP id c68mr13048427qgc.63.1409884907689; Thu, 04 Sep 2014 19:41:47 -0700 (PDT) MIME-Version: 1.0 Received: by 10.224.174.68 with HTTP; Thu, 4 Sep 2014 19:41:27 -0700 (PDT) In-Reply-To: References: From: Yotam Barnoy Date: Thu, 4 Sep 2014 22:41:27 -0400 Message-ID: To: Ocaml Mailing List Content-Type: multipart/alternative; boundary=001a113a672c18df7d050248691e Subject: Re: [Caml-list] help with functors --001a113a672c18df7d050248691e Content-Type: text/plain; charset=UTF-8 I've been given the solution to the problem, so no need to worry about it anymore: I was leaving the inner types of InnerBag and ValueBag abstract. Sorry for the noise. On Thu, Sep 4, 2014 at 9:39 PM, Yotam Barnoy wrote: > I've created a gist at > https://gist.github.com/anonymous/cbfe96b920f08208e1dc to illustrate the > problem. I can't get InnerBag to unify with the ValueBag. This is a very > sparse representation of the code, but it contains all the essential > elements in one file, so you can just try to build it with ocamlc. > > Thanks in advance > Yotam > > > On Thu, Sep 4, 2014 at 5:59 PM, Yotam Barnoy > wrote: > >> Thanks for the reply Gabriel. I can't post the code at this time -- not >> without leaving out a whole bunch of it, in which case getting it to >> compile will be difficult. The pattern should be clear enough, though: >> ocaml uses functors for all complex persistent data structures, and if I >> have a Map.Make(something), and then another functorized module that >> contains Map.Make(something), there should be a way to unify the outer and >> inner Map. That's basically my situation, but ocaml refuses to unify the >> two Map applications. >> >> Also, there are also very few resources online about complex uses of >> functors. Almost every resource touches trivial uses and then moves on to >> other subjects. >> >> >> On Thu, Sep 4, 2014 at 11:12 AM, Gabriel Scherer < >> gabriel.scherer@gmail.com> wrote: >> >>> (voluntarily private reply) >>> >>> Could you send a self-contained source code that can be compiled (.. and >>> maybe raise a type error)? Your code above is good but there are ellipsis >>> that people maybe don't want to have to fill themselves to experiment with >>> your problem. >>> >>> >>> On Thu, Sep 4, 2014 at 3:53 PM, Yotam Barnoy >>> wrote: >>> >>>> Here's an attempt to clarify the question: >>>> >>>> I have a functor F and a functor G. I apply F to module M outside of G >>>> to create F', and within G I also apply F to M to create F''. Additionally, >>>> G is applied to M to create G'. How do I make the compiler understand that >>>> F' outside G' is the same as F'' inside G'? >>>> >>>> Yotam >>>> >>>> >>>> On Wed, Sep 3, 2014 at 1:20 PM, Yotam Barnoy >>>> wrote: >>>> >>>>> Working with ocaml's functional data structures has quickly become a >>>>> job of connecting different functors together, and I'd appreciate some help. >>>>> >>>>> I have the following layout: >>>>> >>>>> module rec OrderedKey : OrderedKeyType = struct >>>>> type t = Value.value_t >>>>> let compare = compare >>>>> let filter_idxs idxs = function >>>>> | Value.VTuple l -> Value.VTuple(list_filter_idxs idxs l) >>>>> | _ -> invalid_arg "not a vtuple" >>>>> end >>>>> >>>>> and ValueBag : IBag.S with type elt = Value.value_t = >>>>> IBag.Make(OrderedKey) >>>>> >>>>> and ValueMMap : IMultimap.S with type elt = Value.value_t and type bag >>>>> = ValueBag.t = >>>>> IMultimap.Make(OrderedKey) >>>>> >>>>> and Value : sig ... type value_t = ... end = Value >>>>> >>>>> The situation is as such: my multimap (IMultimap) contains an internal >>>>> specialization of the IBag functor called an InnerBag. It attempts to >>>>> return said bag, which is equivalent to the external ValueBag in structure. >>>>> However, I don't know how to tell ocaml that the type 'bag' which is >>>>> abstract in IMultimap is exactly the same as the external ValueBag. I tried >>>>> to do that above, but what I get is a mismatch between IMultimap's internal >>>>> InnerBag.t and the external ValueBag.t. >>>>> >>>>> Any help would be appreciated. >>>>> >>>>> Yotam >>>>> >>>>> >>>> >>> >> > --001a113a672c18df7d050248691e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I've been given the solution to the problem, so no nee= d to worry about it anymore: I was leaving the inner types of InnerBag and = ValueBag abstract. Sorry for the noise.


On Thu, Sep 4, 2014 at 9:39 PM, Yotam Ba= rnoy <yotambarnoy@gmail.com> wrote:
I've created a gist at https://gis= t.github.com/anonymous/cbfe96b920f08208e1dc to illustrate the problem. = I can't get=C2=A0 InnerBag to unify with the ValueBag. This is a very s= parse representation of the code, but it contains all the essential element= s in one file, so you can just try to build it with ocamlc.

Thanks in advance<= br>
Yotam=


On Thu, Sep 4, 2014 at 5:59 PM, Yotam Ba= rnoy <yotambarnoy@gmail.com> wrote:
Thanks for the reply Gabrie= l. I can't post the code at this time -- not without leaving out a whol= e bunch of it, in which case getting it to compile will be difficult. The p= attern should be clear enough, though: ocaml uses functors for all complex = persistent data structures, and if I have a Map.Make(something), and then a= nother functorized module that contains Map.Make(something), there should b= e a way to unify the outer and inner Map. That's basically my situation= , but ocaml refuses to unify the two Map applications.

Also, there are also very few resources online about complex uses of fu= nctors. Almost every resource touches trivial uses and then moves on to oth= er subjects.


On Thu, Sep 4, 2014 at 11:12 AM, Gabriel Scherer <gabriel.scherer@= gmail.com> wrote:
(voluntarily private reply)

Could you s= end a self-contained source code that can be compiled (.. and maybe raise a= type error)? Your code above is good but there are ellipsis that people ma= ybe don't want to have to fill themselves to experiment with your probl= em.


On Thu, Sep 4, 2014 at 3:53 PM, Yotam Barnoy <yotambarnoy@gmail.com= > wrote:
Here's an attempt to cl= arify the question:

I have a functor F and a functor G. = I apply F to module M outside of G to create F', and within G I also ap= ply F to M to create F''. Additionally, G is applied to M to create= G'. How do I make the compiler understand that F' outside G' i= s the same as F'' inside G'?

Yotam


On Wed, Sep 3, 2014 at 1:20= PM, Yotam Barnoy <yotambarnoy@gmail.com> wrote:
Working with ocaml's fu= nctional data structures has quickly become a job of connecting different f= unctors together, and I'd appreciate some help.

I have the following layout:

module rec OrderedKey : OrderedKeyType =3D struct<= /div>
=C2=A0 =C2=A0 type t =3D Value.value_t
=C2=A0 =C2=A0 le= t compare =3D compare
=C2=A0 =C2=A0 let filter_idxs idxs =3D func= tion
=C2=A0 =C2=A0 =C2=A0 | Value.VTuple l -> Value.VTuple(lis= t_filter_idxs idxs l)
=C2=A0 =C2=A0 =C2=A0 | _ -> invalid_arg "not a vtuple"
=C2=A0 =C2=A0 end

and ValueBag : IBag.S wi= th type elt =3D Value.value_t =3D
=C2=A0 IBag.Make(OrderedKey)

and ValueMMap : IMultimap.S with type elt =3D Value.= value_t and type bag =3D ValueBag.t =3D
=C2=A0 IMultimap.Make(OrderedKey)

and Value := sig ... type value_t =3D ... end =3D Value

= The situation is as such: my multimap (IMultimap) contains an internal spec= ialization of the IBag functor called an InnerBag. It attempts to return sa= id bag, which is equivalent to the external ValueBag in structure. However,= I don't know how to tell ocaml that the type 'bag' which is ab= stract in IMultimap is exactly the same as the external ValueBag. I tried t= o do that above, but what I get is a mismatch between IMultimap's inter= nal InnerBag.t and the external ValueBag.t.

Any help would be appreciated.

Yotam






--001a113a672c18df7d050248691e--