caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Manifest types in module type inclusions
@ 2010-12-26  5:19 Markus Mottl
  2010-12-26  5:56 ` Jacques Garrigue
  0 siblings, 1 reply; 2+ messages in thread
From: Markus Mottl @ 2010-12-26  5:19 UTC (permalink / raw)
  To: OCaml List

Hi,

please consider the following code:

-------------------
module M = struct type t = A | B end

module X : sig
(*  type t = M.t = A | B *)
  include module type of M
(*  include module type of M with type t = M.t = A | B *)
end = struct include M end

let () = assert (M.A = X.A)
-------------------

This will fail, because M.A is not of the same type as X.A.  But I
would really like to make the types equivalent.

Using the first commented out line instead of the module type
inclusion will succeed, but then I would not be able to automatically
include any functions potentially contained in module M.  The last
commented out line won't work, because one cannot establish a type
equivalence via a manifest type definition after "with type".  Even
if, I don't think one could override anything else but an abstract
type that way, and we are including a sum type here already.

Does anybody have any suggestions for a workaround?  I suspect this
may be a missing feature.

Regards,
Markus

-- 
Markus Mottl        http://www.ocaml.info        markus.mottl@gmail.com


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

* Re: [Caml-list] Manifest types in module type inclusions
  2010-12-26  5:19 [Caml-list] Manifest types in module type inclusions Markus Mottl
@ 2010-12-26  5:56 ` Jacques Garrigue
  0 siblings, 0 replies; 2+ messages in thread
From: Jacques Garrigue @ 2010-12-26  5:56 UTC (permalink / raw)
  To: Markus Mottl; +Cc: OCaml List

On 2010/12/26, at 14:19, Markus Mottl wrote:
> please consider the following code:
> 
> -------------------
> module M = struct type t = A | B end
> 
> module X : sig
> (*  type t = M.t = A | B *)
>  include module type of M
> (*  include module type of M with type t = M.t = A | B *)
> end = struct include M end
> 
> let () = assert (M.A = X.A)
> -------------------
> 
> This will fail, because M.A is not of the same type as X.A.  But I
> would really like to make the types equivalent.
> 
> Using the first commented out line instead of the module type
> inclusion will succeed, but then I would not be able to automatically
> include any functions potentially contained in module M.  The last
> commented out line won't work, because one cannot establish a type
> equivalence via a manifest type definition after "with type".  Even
> if, I don't think one could override anything else but an abstract
> type that way, and we are including a sum type here already.
> 
> Does anybody have any suggestions for a workaround?  I suspect this
> may be a missing feature.

Unfortunately there is no easy workaround using 3.12.0.
Intuitively at least the 3rd line should work, but a bug prevents this.

In 3.12.1, you should be able to write either the 3rd, or the
simpler following version:

  include module type of M with type t = M.t

This should solve your problem.

Side note: the choice to make "include M" define "type t = A | B"
rather than "type t = M.t = A | B" was done to allow more implementations
(any module defining the same operations as M is allowed, rather
than modules sharing the same representation for types.)
But it resulted in not allowing the code you write here, which was
not intentional.

Jacques Garrigue


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

end of thread, other threads:[~2010-12-26  5:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-26  5:19 [Caml-list] Manifest types in module type inclusions Markus Mottl
2010-12-26  5:56 ` Jacques Garrigue

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