caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: avaron@gmail.com
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Polymorphic variants question
Date: Mon, 04 Sep 2006 08:18:39 +0900 (JST)	[thread overview]
Message-ID: <20060904.081839.38906751.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <90F4D998-FB49-4EA5-81EA-DB0746B10071@gmail.com>

From: Andres Varon <avaron@gmail.com>

> > Just that I don't see how you could possibly enforce the above
> > condition either, without something in the signatures to tell the
> > system that argument sets of B.t and C.t must be disjoint.
> > Or you are telling me that, as you already included "type t = [B.t |
> > C.t]" in the return type of the functor, there is already an implicit
> > constraint on B.t and C.t. This is right indeed, but the point is that
> > you need some logic to handle this constraint; and you want also to be
> > able to create unions without necessarily writing it in the outside
> > signature.
> 
> I haven't modified the ocaml compiler to be able to make that  
> functor, but I have made the small change (or I made a small change  
> and left a bunch of holes!), so that unions must always be disjoint,  
> you can still use the intersection of type by refining one, but  
> unions should always be disjoint (ok, it is turned on with a flag in  
> the compiler). This is a desirable feature in the context of my  
> program, though I can see that making unions from compatible types is  
> also desirable in other contexts.
> 
> I want to add exactly the assumption you mention, if type t = [B.t |  
> C.t] is included in the type of the functor, that implicit constraint  
> is there, otherwise, what will be the proper behavior of the function  
> for a tag that appears in both C.t and B.t? one overrides the other?  
> It seems to me that in the context of that functor, the union must be  
> of disjoint types, not only for that problematic case of yours, but  
> even for the compatible cases, otherwise, I cannot guarantee that the  
> functor that composes two modules that have even been proved correct,  
> will still be correct; if they are disjoint, I clean my hands with  
> many problematic corners.

Interesting point. I'm still convinced that, as polymorphic variants
provide mixed union by opposition to the disjoint union of normal
variants, it would be a pity to restrict them by default.

But since our idea is to add compatibility constraints to functor
parameters, to explicitly allow combining two abstract variant types,
it is actually easy to extend compatibilities with exclusive ones.
That is, to allow mixed sum you would write (omiting the private's)

module A(B : sig type t = [> ] end)(C : sig type t = [> ] ~ [B.t]) = ...

The above  ~ [B.t]  means that C.t should be compatible with C.t
(common tags should have identical types), allowing to create the
union [B.t | C.t].

To accomodate your needs for disjoint sum, we just need a small
variation on that

module A(B : sig type t = [> ] end)(C : sig type t = [> ] ~ [~B.t]) = ...

Here  ~ [~B.t] would mean that C.t shouldn't contain any tag from B.t,
enforcing that they are disjoint. Of course this still allows creating
the union [B.t | C.t].

Jacques Garrigue


  reply	other threads:[~2006-09-03 23:19 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-01 17:31 David Allsopp
2006-09-01 18:33 ` Chris King
2006-09-01 19:00   ` [Caml-list] " skaller
2006-09-01 19:57     ` David Allsopp
2006-09-01 20:40       ` Jacques Carette
2006-09-01 18:40 ` [Caml-list] " Olivier Andrieu
2006-09-01 19:26 ` Jon Harrop
2006-09-01 19:29 ` skaller
2006-09-01 20:49   ` Andres Varon
2006-09-02 11:16     ` Jacques Garrigue
2006-09-03  1:22       ` Andres Varon
2006-09-03  9:08         ` Jacques Garrigue
2006-09-03 15:00           ` Andres Varon
2006-09-03 23:18             ` Jacques Garrigue [this message]
2006-09-03  0:48   ` [Caml-list] Polymorphic variants problem skaller
2006-09-03  1:12     ` Andres Varon
  -- strict thread matches above, loose matches on Subject: below --
2001-07-20  1:05 [Caml-list] polymorphic variants question John Max Skaller

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=20060904.081839.38906751.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=avaron@gmail.com \
    --cc=caml-list@yquem.inria.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).