<?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/6d663c04999aebd27b79a847c5db949d"
  from="Gerd Stolpmann &lt;info@g...&gt;"
  author="Gerd Stolpmann"
  date="2002-07-09T12:20:46"
  subject="Re: [Caml-list] Pxp objects inside class definition"
  prev="2002/07/6982dabc6e9541815755c57458ab4117"
  next="2002/07/086268fbbe8e02b0a0ba309f45dfef2d"
  prev-in-thread="2002/07/6982dabc6e9541815755c57458ab4117"
  prev-thread="2002/07/ced740f9b22e4ed570de853782df4585"
  next-thread="2002/07/44bb761bf353031a2a1eed29d5966ee0"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Pxp objects inside class definition">
<msg 
  url="2002/07/6982dabc6e9541815755c57458ab4117"
  from="Gaurav Chanda &lt;gaurav_chanda@l...&gt;"
  author="Gaurav Chanda"
  date="2002-07-09T08:35:56"
  subject="[Caml-list] Pxp objects inside class definition">
<msg 
  url="2002/07/6d663c04999aebd27b79a847c5db949d"
  from="Gerd Stolpmann &lt;info@g...&gt;"
  author="Gerd Stolpmann"
  date="2002-07-09T12:20:46"
  subject="Re: [Caml-list] Pxp objects inside class definition">
</msg>
</msg>
</thread>

<contents>
Gaurav Chanda wrote:
&gt; Hello
&gt; 
&gt; I am using the Polymorphic XML Parser (PXP) to parse XML documents. I have made 2 files : point.ml and point.mli, which contain simple class definitions.
&gt; 
&gt; The file point.mli contains:
&gt; 
&gt; open Pxp_yacc ;
&gt; open Pxp_document ;
&gt; open Pxp_types ;
&gt; 
&gt; class type point_sig =
&gt;         object
&gt;                 value mutable x : Pxp_document.node 'a;
&gt;         end;
&gt; 
&gt; class point : point_sig ;
&gt; 
&gt; 
&gt; The file point.ml contains:
&gt; 
&gt; open Pxp_yacc ;
&gt; open Pxp_document ;
&gt; open Pxp_types ;
&gt; 
&gt; class type point_sig =
&gt;         object
&gt;                 value mutable x : Pxp_document.node 'a;
&gt;         end ;
&gt; 
&gt; value def = "&lt;def&gt;&lt;/def&gt;" ;
&gt; value def = parse_wfdocument_entity default_config (from_string def) default_spec ;
&gt; value defr = def#root ;
&gt; 
&gt; class point:point_sig =
&gt;         object
&gt;                 value mutable x = defr;
&gt;         end;
&gt; 
&gt; I get an error message while compilation. My compilation command is : 
&gt; ocamlopt -pp "camlp4r pa_extend.cmo" -I +camlp4 -I Ty/ -I /usr/lib/ocaml/site-lib/netstring -I /usr/lib/ocaml/site-lib/pxp-engine  -I /usr/lib/ocaml/site-lib/pxp-lex-iso88591/ -c point.mli point.ml
&gt; 
&gt; 
&gt; The error message is : 
&gt; 
&gt; File "point.ml", line 15, characters 8-67:
&gt; The class type
&gt;   object
&gt;     val mutable x :
&gt;       ('a Pxp_document.node Pxp_document.extension as 'a) Pxp_document.node
&gt;   end
&gt; is not matched by the class type point_sig
&gt; The class type
&gt;   object
&gt;     val mutable x :
&gt;       ('a Pxp_document.node Pxp_document.extension as 'a) Pxp_document.node
&gt;   end
&gt; is not matched by the class type
&gt;   object
&gt;     val mutable x :
&gt;       ('a Pxp_document.node #Pxp_document.extension as 'a) Pxp_document.node
&gt;   end
[...]
&gt; 
&gt; I am not being able to define PXP objects inside classes. Could you help me solve this problem ?

Hi Garuav,

(the following in classic syntax)

the problem is that  'a Pxp_document.node  is not the full type, because 
there is a constraint on the parameter of the class Pxp_document.node,
and the compiler correctly augments the type such that it reads
('a Pxp_document.node #Pxp_document.extension as 'a) Pxp_document.node.
However, defr has the type
('a Pxp_document.node Pxp_document.extension as 'a) Pxp_document.node,
which is not the same. This is all the long error message wants to tell
you.

The solution is quite simple: Use the complete type instead of
'a Pxp_document.node, i.e.

class type point_sig =
object
   val mutable x :
    ('a Pxp_document.node Pxp_document.extension as 'a) Pxp_document.node
end

Sorry that the types of PXP are that complicated.
('a Pxp_document.node Pxp_document.extension as 'a) Pxp_document.node
reflects the fact that nodes have extensions, and the extensions are
recursively bound to their nodes. This is sometimes a bit unhandy.

Gerd
-- 
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
------------------------------------------------------------

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

