Version française
Home     About     Download     Resources     Contact us    
Browse thread
Private types in 3.11, again
[ 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] Private types in 3.11, again
Hi Jacques,

From: Jacques Carette <carette@mcmaster.ca>
> Hmmm, a variant of your code may be exhibiting a bug in ocaml 3.11.0.
> 
> In your signature, change the +'a t signature to
>     type +'a t = private [< elem_t ]
> and remove all annotations from the definition of sprint2.  Then, as 
> defined, one gets the error message
> 
> File "bug2.ml", line 26, characters 0-223:
> Error: Signature mismatch:
>        Modules do not match:
>          sig
>            val sprint2 :
>              ([< `Bold of 'a list | `Text of string ] as 'a) -> string
>          end
>        is not included in
>          sig val sprint2 : 'a Node.t -> string end
>        Values do not match:
>          val sprint2 :
>            ([< `Bold of 'a list | `Text of string ] as 'a) -> string
>        is not included in
>          val sprint2 : 'a Node.t -> string
> 
> which is not very informative, especially since expanding 'a Node.t 
> gives exactly what the compiler reports as the first argument of sprint2.

Unfortunately, type errors for private row types can be hard to
understand when the types themselves are complex.
As I pointed in my answer to Dario, the private row type Node.t has to
be recursive for it to be an instance of a recursive type.
[< elem_t] does not define a recursive type, but just adds a row
variable on its outermost variant.

> To coax the compiler to be more helpful, on places the definition of 
> sprint2 outside a module (but still in the same file as Node), and 
> instead the result is:
> 
> File "bug2.ml", line 30, characters 26-29:
> Error: This expression has type Node.elem_t list but is here used with type
>          'a Node.t list
>        Type Node.elem_t = [ `Bold of Node.elem_t list | `Text of string ]
>        is not compatible with type
>          'a Node.t = [< `Bold of Node.elem_t list | `Text of string ]
>        Types for tag `Text are incompatible
> 
> [That point to the seq in List.map sprintf2 seq].  Here is where the 
> potential bug is: how is string incompatible with string?
> [If this is a bug, I'll add it to the database]

The bug is in only in the error message; which seems another instance
of the problem you reported in your previous mail.
There is however a real type error, because Node.t, as it has a
private row, cannot be an instance of the fixed type elem_t.

Cheers,

Jacques Garrigue