<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/07/0753c3188698d9ea0f77236a0e41c552"
  from="Brian Smith &lt;brian-l-smith@u...&gt;"
  author="Brian Smith"
  date="2002-07-08T01:25:16"
  subject="[Caml-list] Polymorphic methods (longest error message ever!)"
  prev="2002/07/2702b480e76a128d5e149a4d57a81363"
  next="2002/07/769799bb920dee01c56f1972fd80a499"
  next-in-thread="2002/07/769799bb920dee01c56f1972fd80a499"
  prev-thread="2002/07/bc2a965ab496aafdf2907a6d9bf85822"
  next-thread="2002/07/8d12ac2d99463ad68064b36be9eba6e9"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Polymorphic methods (longest error message ever!)">
<msg 
  url="2002/07/0753c3188698d9ea0f77236a0e41c552"
  from="Brian Smith &lt;brian-l-smith@u...&gt;"
  author="Brian Smith"
  date="2002-07-08T01:25:16"
  subject="[Caml-list] Polymorphic methods (longest error message ever!)">
<msg 
  url="2002/07/769799bb920dee01c56f1972fd80a499"
  from="John Max Skaller &lt;skaller@o...&gt;"
  author="John Max Skaller"
  date="2002-07-08T02:08:15"
  subject="Re: [Caml-list] Polymorphic methods (longest error message ever!)">
</msg>
<msg 
  url="2002/07/5a7ec0755664b20f2ebf374c1c84515e"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2002-07-08T02:53:12"
  subject="Re: [Caml-list] Polymorphic methods (longest error message ever!)">
</msg>
<msg 
  url="2002/07/c1897db7ead6b5e80f6785eec2a57004"
  from="Brian Smith &lt;brian-l-smith@u...&gt;"
  author="Brian Smith"
  date="2002-07-09T06:23:10"
  subject="Re: [Caml-list] Polymorphic methods (syntax)">
</msg>
</msg>
</thread>

<contents>
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 = [&gt; `Node of 'a node_type]
      end;;
    class ['a] node : ['a] node_type =
      object (self)
        method as_variant : 'a = `Node (self :&gt; '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 : [&gt; `Node of node_type]
    end;;
  class type node_type =
     object method as_variant : [&gt; `Node of node_type] end

  # class node : node_type = object (self)
      method as_variant = `Node (self :&gt; node_type)
    end;;
                                 ^^^^
  This expression cannot be coerced to type
  node_type = &lt; as_variant : 'a. [&gt; `Node of node_type] as 'a &gt;;
  it has type &lt; as_variant : 'c; .. &gt; as 'b but is here used with type 'b

  # class node : node_type = object (self)
      method as_variant : 'a. [&gt; `Node of node_type] as 'a
                        = `Node (self :&gt;  node_type)
    end;;
The class type object method as_variant : [&gt; `Node of node_type] end
is not matched by the class type node_type
The class type object method as_variant : [&gt; `Node of node_type] end
is not matched by the class type
   object method as_variant : [&gt; `Node of node_type] end
The method as_variant has type 'a. [&gt; `Node of node_type] as 'a
but is expected to have type 'b. [&gt; `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

</contents>

</message>

