[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Gerd Stolpmann <info@g...> |
| Subject: | Re: [Caml-list] Pxp objects inside class definition |
Gaurav Chanda wrote:
> Hello
>
> 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.
>
> The file point.mli contains:
>
> open Pxp_yacc ;
> open Pxp_document ;
> open Pxp_types ;
>
> class type point_sig =
> object
> value mutable x : Pxp_document.node 'a;
> end;
>
> class point : point_sig ;
>
>
> The file point.ml contains:
>
> open Pxp_yacc ;
> open Pxp_document ;
> open Pxp_types ;
>
> class type point_sig =
> object
> value mutable x : Pxp_document.node 'a;
> end ;
>
> value def = "<def></def>" ;
> value def = parse_wfdocument_entity default_config (from_string def) default_spec ;
> value defr = def#root ;
>
> class point:point_sig =
> object
> value mutable x = defr;
> end;
>
> I get an error message while compilation. My compilation command is :
> 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
>
>
> The error message is :
>
> File "point.ml", line 15, characters 8-67:
> The class type
> object
> val mutable x :
> ('a Pxp_document.node Pxp_document.extension as 'a) Pxp_document.node
> end
> is not matched by the class type point_sig
> The class type
> object
> val mutable x :
> ('a Pxp_document.node Pxp_document.extension as 'a) Pxp_document.node
> end
> is not matched by the class type
> object
> val mutable x :
> ('a Pxp_document.node #Pxp_document.extension as 'a) Pxp_document.node
> end
[...]
>
> 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