Version française
Home     About     Download     Resources     Contact us    
Browse thread
Polymorphic variants question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] Polymorphic variants question
From: Andres Varon <avaron@gmail.com>
Subject: Re: [Caml-list] Polymorphic variants question
Date: Sat, 2 Sep 2006 21:22:55 -0400

> 
> On Sep 2, 2006, at 7:16 AM, Jacques Garrigue wrote:
> 
> > Just that the concrete type is much simpler.
> > The abstract type does not work directly, as you need a way to ensure
> > that B.t and C.t are compatible. Otherwise, one could write
> >
> > module D = A(struct type t = [ `A of int] ... end)
> >             (struct type t = [ `A of string] ... end)
> >
> > which is clearly incorrect.
> 
> I use a more restricted version of polymorphic variants to ensure  
> that two functions that are being composed through a match in the  
> style of the question do not share a tag (and so one function will  
> not override the expected behavior of the second one), even if the  
> tags are fully compatible; being this the case, your example cannot  
> occur.
> 
> I am not an expert in programming languages, and I cannot see - in  
> this restricted case - a reason why that functor could still be  
> problematic. Is there some?

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.

Jacques Garrigue