caml-list - the Caml user's mailing list
 help / Atom feed
* [Caml-list] include two module implementations sharing the same type definitions
@ 2018-11-29  8:54 Yann Régis-Gianas
  2018-11-29  9:03 ` Danny Gratzer
  0 siblings, 1 reply; 5+ messages in thread
From: Yann Régis-Gianas @ 2018-11-29  8:54 UTC (permalink / raw)
  To: Ocaml Mailing List

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

Dear OCaml module hackers,

the recently polished "substitution inside type signature" (described in
Sec 8.11 in the manual) is a real improvement to modularize module
signature developments.

Yet, it seems to me that "include" at the level of module implementations
is preventing us to unleash the full composability power of "include" at
the level of signature. Consider the following example:

``
module type A = sig type t end

module type B = sig type t end

type u = U

module AI : A with type t = u = struct
  type t = u
end

module BI : B with type t = u = struct
  type t = u
end

module ABI : sig
  include A
  include B with type t := t
end = struct
  include AI
  include BI (* This include unfortunately triggers:

Error: Multiple definition of the type name t.
       Names must be unique in a given structure or signature.

  *)
end
``

I have two questions:

Would it make sense to allow module implementation inclusion to introduce
multiple definitions of a given type name as long as these definitions are
equivalent?

Is there an idiom to work around this (apparent) limitation?

Cheers,
-- 
Yann Régis-Gianas

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list https://inbox.ocaml.org/caml-list
Forum: https://discuss.ocaml.org/
Bug reports: http://caml.inria.fr/bin/caml-bugs

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

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

* Re: [Caml-list] include two module implementations sharing the same type definitions
  2018-11-29  8:54 [Caml-list] include two module implementations sharing the same type definitions Yann Régis-Gianas
@ 2018-11-29  9:03 ` Danny Gratzer
  2018-11-29  9:07   ` Yann Régis-Gianas
  2018-11-29  9:09   ` Frédéric Bour
  0 siblings, 2 replies; 5+ messages in thread
From: Danny Gratzer @ 2018-11-29  9:03 UTC (permalink / raw)
  To: yrg; +Cc: caml-list

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

Hello,

Perhaps I'm overlooking something but replacing

    include BI

with

    include (BI : B with type t := t)

seems like a reasonable fix to me.

Danny

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list https://inbox.ocaml.org/caml-list
Forum: https://discuss.ocaml.org/
Bug reports: http://caml.inria.fr/bin/caml-bugs

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

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

* Re: [Caml-list] include two module implementations sharing the same type definitions
  2018-11-29  9:03 ` Danny Gratzer
@ 2018-11-29  9:07   ` Yann Régis-Gianas
  2018-11-29  9:09   ` Frédéric Bour
  1 sibling, 0 replies; 5+ messages in thread
From: Yann Régis-Gianas @ 2018-11-29  9:07 UTC (permalink / raw)
  To: Danny Gratzer; +Cc: caml-list

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

Hello Danny,

and thank you! That is clearly a nice work around even though it may
require to introduce unnecessary module signatures for the only purpose of
composing module implementations.

Cheers,

Le jeu. 29 nov. 2018 à 10:02, Danny Gratzer <danny.gratzer@gmail.com> a
écrit :

> Hello,
>
> Perhaps I'm overlooking something but replacing
>
>     include BI
>
> with
>
>     include (BI : B with type t := t)
>
> seems like a reasonable fix to me.
>
> Danny
>
-- 
Yann Régis-Gianas

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list https://inbox.ocaml.org/caml-list
Forum: https://discuss.ocaml.org/
Bug reports: http://caml.inria.fr/bin/caml-bugs

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

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

* Re: [Caml-list] include two module implementations sharing the same type definitions
  2018-11-29  9:03 ` Danny Gratzer
  2018-11-29  9:07   ` Yann Régis-Gianas
@ 2018-11-29  9:09   ` Frédéric Bour
  2018-11-29  9:13     ` Yann Régis-Gianas
  1 sibling, 1 reply; 5+ messages in thread
From: Frédéric Bour @ 2018-11-29  9:09 UTC (permalink / raw)
  To: danny.gratzer; +Cc: yrg, caml-list

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

1) In all generality,

  include (BI : module type of struct include BI end with type t := t)

will work if you haven't defined `module type B` or if `BI` exports other
types (say u) and you need to preserve equalities (BI.u = B.u).

2) Changes have been made to the module system in the trunk version of
OCaml. The original code should be accepted without any change.

On Thu, Nov 29, 2018 at 10:03 AM Danny Gratzer <danny.gratzer@gmail.com>
wrote:

> Hello,
>
> Perhaps I'm overlooking something but replacing
>
>     include BI
>
> with
>
>     include (BI : B with type t := t)
>
> seems like a reasonable fix to me.
>
> Danny
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list https://inbox.ocaml.org/caml-list
Forum: https://discuss.ocaml.org/
Bug reports: http://caml.inria.fr/bin/caml-bugs

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

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

* Re: [Caml-list] include two module implementations sharing the same type definitions
  2018-11-29  9:09   ` Frédéric Bour
@ 2018-11-29  9:13     ` Yann Régis-Gianas
  0 siblings, 0 replies; 5+ messages in thread
From: Yann Régis-Gianas @ 2018-11-29  9:13 UTC (permalink / raw)
  To: Frédéric Bour; +Cc: danny.gratzer, caml-list

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

Thank you Frédéric!

Le jeu. 29 nov. 2018 à 10:08, Frédéric Bour <defree@gmail.com> a écrit :

> 1) In all generality,
>
>   include (BI : module type of struct include BI end with type t := t)
>
> will work if you haven't defined `module type B` or if `BI` exports other
> types (say u) and you need to preserve equalities (BI.u = B.u).
>
> 2) Changes have been made to the module system in the trunk version of
> OCaml. The original code should be accepted without any change.
>
> On Thu, Nov 29, 2018 at 10:03 AM Danny Gratzer <danny.gratzer@gmail.com>
> wrote:
>
>> Hello,
>>
>> Perhaps I'm overlooking something but replacing
>>
>>     include BI
>>
>> with
>>
>>     include (BI : B with type t := t)
>>
>> seems like a reasonable fix to me.
>>
>> Danny
>>
> --
Yann Régis-Gianas

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list https://inbox.ocaml.org/caml-list
Forum: https://discuss.ocaml.org/
Bug reports: http://caml.inria.fr/bin/caml-bugs

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

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

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-29  8:54 [Caml-list] include two module implementations sharing the same type definitions Yann Régis-Gianas
2018-11-29  9:03 ` Danny Gratzer
2018-11-29  9:07   ` Yann Régis-Gianas
2018-11-29  9:09   ` Frédéric Bour
2018-11-29  9:13     ` Yann Régis-Gianas

caml-list - the Caml user's mailing list

Archives are clonable: git clone --mirror https://inbox.ocaml.org/caml-list

AGPL code for this site: git clone https://public-inbox.org/ public-inbox