caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: brian-l-smith@uiowa.edu
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Polymorphic methods (longest error message ever!)
Date: Mon, 08 Jul 2002 11:53:01 +0900	[thread overview]
Message-ID: <20020708115301R.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <3D28E9F8.5020308@uiowa.edu>

From: Brian Smith <brian-l-smith@uiowa.edu>

> First of all, where can I find some documentation about the CVS versino 
> of O'Caml? Is the documentation kept in CVS too?

Yes, but it is not public.
Anyway, it is not updated simultaneously with the source, so you
wont't find the documentation for a new feature there immediately.
So basically, new features in CVS are given as is, without other
documentation than asking the developpers.

In the present case, the release is probably not too far away, so you
should not have to wait too long.

Until that, for polymorphic methods, there are examples in
testlabl/poly.ml, but it's about all.

> Anyway, on to the problem at hand:
> That works fine in O'Caml 3.04. But, I want to use the new polymorphic 
> method feature in O'Caml 3.04+15. So I tried:
> 
>   # class type node_type =  object
>       method as_variant : [> `Node of node_type]
>     end;;
>   class type node_type =
>      object method as_variant : [> `Node of node_type] end
> 
>   # class node : node_type = object (self)
>       method as_variant = `Node (self :> node_type)
>     end;;
>                                  ^^^^
>   This expression cannot be coerced to type
>   node_type = < as_variant : 'a. [> `Node of node_type] as 'a >;
>   it has type < as_variant : 'c; .. > as 'b but is here used with type 'b

That one is correct behaviour: as_variant is inferred to be
monomorphic, since in the first pass the checker doesn't look inside
method, where is your only type annotation.
(Unfortunately the node: node_type constraint is only applied
afterwards, applying it early being rather complex.)

>   # class node : node_type = object (self)
>       method as_variant : 'a. [> `Node of node_type] as 'a
>                         = `Node (self :>  node_type)
>     end;;
> The class type object method as_variant : [> `Node of node_type] end
> is not matched by the class type node_type
> The class type object method as_variant : [> `Node of node_type] end
> is not matched by the class type
>    object method as_variant : [> `Node of node_type] end
> The method as_variant has type 'a. [> `Node of node_type] as 'a
> but is expected to have type 'b. [> `Node of node_type] as 'b
> The universal variable 'b would escape its scope
> 
> I have no idea what the error message means. To me, it is saying that 
> class "node" doesn't match class type "node_type" even though everything 
> has exactly the same type. Could somebody please explain it to me? What 
> is the correct way of doing the above?

As skaller says, this is hardly a long message :-)
It is also clearly wrong: it tells you that two identical types are
incompatible.
The problem seems to come from the node : node_type part. The
following version works:

# class node = object (self)
    method as_variant : 'a. [> `Node of node_type] as 'a
                      = `Node (self :>  node_type)
  end;;
class node : object method as_variant : [> `Node of node_type] end

And that shorter one also:
# class node = object (self : #node_type)
    method as_variant = `Node (self :> node_type)
  end;;
class node : object method as_variant : [> `Node of node_type] end

Thank you for the bug report, I'll try to correct it.

      Jacques
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2002-07-08  2:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-08  1:25 Brian Smith
2002-07-08  2:08 ` John Max Skaller
2002-07-08  2:53 ` Jacques Garrigue [this message]
2002-07-09  6:23 ` [Caml-list] Polymorphic methods (syntax) Brian Smith

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=20020708115301R.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=brian-l-smith@uiowa.edu \
    --cc=caml-list@inria.fr \
    /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).