caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: carette@mcmaster.ca
Cc: darioteixeira@yahoo.com, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Private types in 3.11, again
Date: Wed, 21 Jan 2009 19:48:27 +0900 (JST)	[thread overview]
Message-ID: <20090121.194827.214243292.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <49760A0C.5080204@mcmaster.ca>

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


  parent reply	other threads:[~2009-01-21 10:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-15 17:31 Dario Teixeira
2009-01-19 15:09 ` [Caml-list] " Dario Teixeira
2009-01-20 16:33   ` Dario Teixeira
2009-01-20 17:29     ` Jacques Carette
2009-01-20 17:48       ` Dario Teixeira
2009-01-21 10:48       ` Jacques Garrigue [this message]
2009-01-21 10:38     ` Jacques Garrigue
2009-01-21 13:22   ` Jacques Garrigue
2009-01-21 19:11     ` Dario Teixeira
2009-01-21 20:17       ` Gabriel Kerneis
2009-01-21 21:52         ` GADTs in Ocaml (was: Private types in 3.11, again) Dario Teixeira
2009-01-22  1:36       ` [Caml-list] Private types in 3.11, again Jacques Garrigue
2009-01-26 15:13 Dario Teixeira

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090121.194827.214243292.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@yquem.inria.fr \
    --cc=carette@mcmaster.ca \
    --cc=darioteixeira@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).