Version française
Home     About     Download     Resources     Contact us    
Browse thread
difference of [< `A of & int] and [< `A of int] ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Hendrik Tews <tews@o...>
Subject: Re: [Caml-list] difference of [< `A of & int] and [< `A of int] ?

Thanks for this quick and enlightening answer!

Jacques Garrigue writes:
   Date: Tue, 21 Sep 2010 21:41:01 +0900
   Subject: Re: [Caml-list] difference of [< `A of & int] and [< `A of int] ?
   
   > [< `A of & int]
   
   This is an (impossible) conjunctive type. 
   Basically it says that `A is both a constant constructor (taking no argument),
   and a constructor taking an argument of type int.

Actually, this type expression is not covered by the grammar in
the reference manual. The rule

   tag-spec-full ::= `tag-name  [ of typexpr ]  { & typexpr }

does not produce it, because typexpr cannot produce the empty
string.

I believe a sentence about this special case in the manual would
be helpful.

   > File "test/x.ml", line 1, characters 0-1:
   > Error: The implementation test/x.ml
   >       does not match the interface (inferred signature):
   >       Type declarations do not match:
   >         type 'a t = 'a constraint 'a = [< `A of & int ]
   >       is not included in
   >         type 'a t = 'a constraint 'a = [< `A of & int ]
   
   Err, it is actually a feature, but I agree this is not very intuitive.
   When checking types against an interface, such conjunctive types are
   not allowed. So the type checker attemps to unify all possibilities, but
   since no argument is not unifiable with anything else, it fails.
   Unfortunately, the error message is not very explicit about the cause.
   
However, the following impossible type

   type 'a t = [< `A of int & string] as 'a

is accepted by the compiler. Is there a reason for treating these
two impossible types differently?

Bye,

Hendrik