caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] help with functors
@ 2014-09-03 17:20 Yotam Barnoy
  2014-09-04 13:53 ` Yotam Barnoy
  0 siblings, 1 reply; 4+ messages in thread
From: Yotam Barnoy @ 2014-09-03 17:20 UTC (permalink / raw)
  To: Ocaml Mailing List

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

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

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] help with functors
  2014-09-03 17:20 [Caml-list] help with functors Yotam Barnoy
@ 2014-09-04 13:53 ` Yotam Barnoy
       [not found]   ` <CAPFanBHS1-DiuitQpGwX_Z=tiNm6_bJd8m=+S0XT2gvixBeFQA@mail.gmail.com>
  0 siblings, 1 reply; 4+ messages in thread
From: Yotam Barnoy @ 2014-09-04 13:53 UTC (permalink / raw)
  To: Ocaml Mailing List

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

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 <yotambarnoy@gmail.com> 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
>
>

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] help with functors
       [not found]     ` <CAN6ygOnZP9SOYiN1mPN3ZLQ9cT8F6pgyDctcj4OxUXyqfwmUuA@mail.gmail.com>
@ 2014-09-05  1:39       ` Yotam Barnoy
  2014-09-05  2:41         ` Yotam Barnoy
  0 siblings, 1 reply; 4+ messages in thread
From: Yotam Barnoy @ 2014-09-05  1:39 UTC (permalink / raw)
  To: Ocaml Mailing List

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

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 <yotambarnoy@gmail.com> 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 <yotambarnoy@gmail.com>
>> 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 <yotambarnoy@gmail.com>
>>> 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
>>>>
>>>>
>>>
>>
>

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] help with functors
  2014-09-05  1:39       ` Yotam Barnoy
@ 2014-09-05  2:41         ` Yotam Barnoy
  0 siblings, 0 replies; 4+ messages in thread
From: Yotam Barnoy @ 2014-09-05  2:41 UTC (permalink / raw)
  To: Ocaml Mailing List

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

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 <yotambarnoy@gmail.com> 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 <yotambarnoy@gmail.com>
> 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 <yotambarnoy@gmail.com>
>>> 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 <yotambarnoy@gmail.com>
>>>> 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
>>>>>
>>>>>
>>>>
>>>
>>
>

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-09-05  2:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-03 17:20 [Caml-list] help with functors Yotam Barnoy
2014-09-04 13:53 ` Yotam Barnoy
     [not found]   ` <CAPFanBHS1-DiuitQpGwX_Z=tiNm6_bJd8m=+S0XT2gvixBeFQA@mail.gmail.com>
     [not found]     ` <CAN6ygOnZP9SOYiN1mPN3ZLQ9cT8F6pgyDctcj4OxUXyqfwmUuA@mail.gmail.com>
2014-09-05  1:39       ` Yotam Barnoy
2014-09-05  2:41         ` Yotam Barnoy

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).