Version française
Home     About     Download     Resources     Contact us    
Browse thread
Implicitely abstracted type
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alain Frisch <alain@f...>
Subject: Re: [Caml-list] Implicitely abstracted type
On 12/16/2010 02:31 PM, Louis Gesbert wrote:
> What happens is that a sum-type defined in a module can implicitely be
> turned into abstract because of its inner contents.

Here is an explanation of this behavior. When applying a functor of type 
functor(X:S1) -> S2 to a module of type T, the module type for the 
result can be obtained in two different ways:

(1) T is a path: the module type is obtained by substituting X with T in S2.

(2) T is not a path: the module type is obtained by computing the 
smallest supertype of S2 that doesn't contain X anymore (under the extra 
assumption that X has type T).


In your example, you are in case (2), and the only way (of which the 
compiler is aware) to get rid of the dependency on the functor's formal 
argument is to turn a concrete type declaration into an abstract one. If 
you are interested in the implementation, this happens in the function 
Ctype.nondep_type_decl (where a Not_found exception raised by 
nondep_type_rec is turned into a Type_abstract).

Admittedly, this fallback behavior of turning automatically a concrete 
type declaration into an abstract one is not completely natural. As far 
as I can tell, it would be straightforward to add a warning in this 
situation.  Do you want to fill a feature request?


Alain