[Ocaml-pxp-users] Problem with tree manipulation

Dario Teixeira darioteixeira at yahoo.com
Thu Jul 30 13:18:33 PDT 2009


Hi,

I am getting type-checker errors on a simple function that manipulates a
PXP document tree.  The function takes as parameter a 'parent' node and
one of its children, named 'child'.  All it does is create a new element
'paragraph' whose parent is 'parent' and whose child is 'child' (the latter
therefore gets a new parent).  In other words, the function transforms the
hierarchy "parent -> child", into "parent -> paragraph -> child".  Its
(simplified) code is as follows:

let foobar parent child =
	let paragraph = child#create_element child#dtd (T_element "p") []
	in	parent#insert_nodes ~pos:child#node_position [paragraph];
		child#remove ();
		paragraph#append_node child

The error is the following:

Error: This expression has type
         'a Pxp_document.extension Pxp_document.node as 'a
       but an expression was expected of type
         < create_element : 'c ->
                            Pxp_document.node_type ->
                            'd list ->
                            (< append_node : 'b -> unit; .. > as 'e);
           data : Lambdoc_core.Basic.plain_t; dtd : 'c;
           insert_nodes : pos:'f -> 'e list -> 'g; node_position : 'f;
           node_type : Pxp_document.node_type;
           optional_string_attribute : string -> string option;
           position : 'h * int * 'i; remove : unit -> 'j;
           required_string_attribute : string -> Lambdoc_core.Basic.raw_t;
           sub_nodes : 'b list; .. >
         as 'b
       Types for method create_element are incompatible


Now, it's my understanding that create_element essentially uses the given node
as a template from which a new node is created (and I'm guessing I could have
invoked it on 'parent' instead of 'child' with the same effect).  Also, the
program type-checks as long as I don't invoke parent#insert_nodes.

Any thoughts on what I am doing wrong here?  (Many thanks in advance!)

Best regards,
Dario Teixeira



      


More information about the Ocaml-pxp-users mailing list