caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brian Smith <brian-l-smith@uiowa.edu>
To: OCaml Mailing list <caml-list@inria.fr>
Subject: [Caml-list] Polymorphic methods (longest error message ever!)
Date: Sun, 07 Jul 2002 20:25:12 -0500	[thread overview]
Message-ID: <3D28E9F8.5020308@uiowa.edu> (raw)

Hi everybody,

First of all, where can I find some documentation about the CVS versino 
of O'Caml? Is the documentation kept in CVS too? Anyway, on to the 
problem at hand:

I have a class like this:
    class type ['a] node_type =
      object
        method as_variant : 'a
        constraint 'a = [> `Node of 'a node_type]
      end;;
    class ['a] node : ['a] node_type =
      object (self)
        method as_variant : 'a = `Node (self :> 'a node_type)
      end;;

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

  # 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?

Thanks,
Brian


-------------------
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


             reply	other threads:[~2002-07-08  1:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-08  1:25 Brian Smith [this message]
2002-07-08  2:08 ` John Max Skaller
2002-07-08  2:53 ` Jacques Garrigue
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=3D28E9F8.5020308@uiowa.edu \
    --to=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).