caml-list  

Re: [Caml-list] Private types in 3.11, again

Jacques Carette
Tue, 20 Jan 2009 09:30:42 -0800

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.

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]

Jacques

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs