[Ocaml-pxp-users] Problem with tree manipulation
Gerd Stolpmann
gerd at gerd-stolpmann.de
Tue Aug 11 14:34:23 PDT 2009
I'd suggest not to call create_element to create new elements, but use
the more official way of calling Pxp_document.create_element_node.
Typing of objects is notoriously difficult, especially when there are
optional arguments like for insert_nodes. Without checking this piece of
code in detail, it can easily happen that a single type hint solves your
problem, something like
(paragraph : _ Pxp_document.node)
or similar.
Gerd
Am Donnerstag, den 30.07.2009, 13:18 -0700 schrieb Dario Teixeira:
> 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
>
>
>
>
> _______________________________________________
> Ocaml-pxp-users mailing list
> Ocaml-pxp-users at orcaware.com
> http://www.orcaware.com/mailman/listinfo/ocaml-pxp-users
>
--
------------------------------------------------------------
Gerd Stolpmann, Bad Nauheimer Str.3, 64289 Darmstadt,Germany
gerd at gerd-stolpmann.de http://www.gerd-stolpmann.de
Phone: +49-6151-153855 Fax: +49-6151-997714
------------------------------------------------------------
More information about the Ocaml-pxp-users
mailing list