caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: "Michael Grünewald" <michaelgrunewald@yahoo.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Deleting a type alias while including a module
Date: Fri, 25 Nov 2011 00:53:05 +0100	[thread overview]
Message-ID: <CAPFanBGrmpY5k6WmdAU_o8YzjDa_N_0HU+NvhvaN1EiYa8RpQw@mail.gmail.com> (raw)
In-Reply-To: <4ECE9C09.3030705@yahoo.fr>

Here is how I understand the situation:

> module type XARRAY =
> sig
>  type 'a xarray
>  type 'a t = 'a xarray
> end

> (XArray : XARRAY with type 'a t := 'a XArray.xarray )

>       Type declarations do not match:
>         type 'a t = 'a XArray.xarray
>       is not included in
>         type 'a t = 'a xarray

When you seal a module with a signature that has an abstract type (the
type ('a xarray) in the XARRAY signature), you get a "fresh" abstract
type is a result. The typer is here giving the following complain:
- you told me in the XARRAY signature that ('a t) would always be
equal to ('a xarray)
- in this example you also ask for ('a t) to be equal with 'a
XArray.xarray, the type of the previously defined module
- but by definition the ('a xarray) type of the current sealing is a
fresh abstract type, thus different of all previous types

If you want to equate ('a t = something) while still respecting the
(type 'a t = 'a xarray) signature contract, you have to first make ('a
xarray) a defined type rather than abstract type:

  # module Test = (XArray : XARRAY with type 'a xarray = 'a XArray.xarray);;
  module Test : sig type 'a xarray = 'a XArray.xarray type 'a t = 'a xarray end

Then you can substitute 'a t without breaking the weakened interface contract:

  # module Test = (XArray : XARRAY with type 'a xarray = 'a
XArray.xarray and type 'a t := 'a XArray.xarray);;
  module Test : sig type 'a xarray = 'a XArray.xarray end

If you wish to get an abstract type again, you can seal it after the
fact, but this requires to know the whole result type signature (here
it's only (sig type 'a xarray end)):

# module Test : sig type 'a xarray end = (XArray : XARRAY with type 'a
xarray = 'a XArray.xarray and type 'a t := 'a XArray.xarray);;
module Test : sig type 'a xarray en


2011/11/24 Michael Grünewald <michaelgrunewald@yahoo.fr>:
> As a complement to my previous message, here is a minimal (well, short!)
> example displaying the behavior I cannot go around:
>
> ----8<--- example starts here ----
> module type XARRAY =
> sig
>  type 'a xarray
>  type 'a t = 'a xarray
> end
>
> module XArray : XARRAY =
> struct
>  type 'a xarray = 'a
>  type 'a t = 'a xarray
> end
>
> module UseXArray =
> struct
>  include (XArray : XARRAY with type 'a t := 'a XArray.xarray )
> end
> ----8<---- example ends here ----
> Trying to compile this file yields the following error:
>
> File "include_substitute.ml", line 15, characters 20-61:
> Error: In this `with' constraint, the new definition of t
>       does not match its original definition in the constrained signature:
>       Type declarations do not match:
>         type 'a t = 'a XArray.xarray
>       is not included in
>         type 'a t = 'a xarray
>
> (OCaml 3.12.1 on FreeBSD/amd64)
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>


  reply	other threads:[~2011-11-24 23:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-24 16:35 Michael Grünewald
2011-11-24 19:33 ` Michael Grünewald
2011-11-24 23:53   ` Gabriel Scherer [this message]
2011-11-25  6:52     ` Michael Grünewald

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPFanBGrmpY5k6WmdAU_o8YzjDa_N_0HU+NvhvaN1EiYa8RpQw@mail.gmail.com \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=michaelgrunewald@yahoo.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).