Re: Nethtml.document -> String

Gerd Stolpmann <[email protected]> Sat, 21 May 2005 12:44:57 +0200
Newsgroups gmane.comp.lang.ocaml.lib.net.devel
Message-ID <[email protected]>
Am Samstag, den 21.05.2005, 00:42 +0200 schrieb Rakotomandimby (R12y)
Mihamina:
> Hello,
> 
> I made these things and I cant find what is my mistake. Would you help
> me? The goal is to print the HTML page to the screen just to debug for
> small applications, and if it works well I could use it and see how it
> behaves on the cgi script. I try to output a Nethtml.document to a
> Buffer, and then print the content of the buffer.
> 
> # let page = Nethtml.Element (  "body", [], [Nethtml.Data("rien")]);;
> val page : Nethtml.document =
>   Nethtml.Element ("body", [], [Nethtml.Data "rien"])
> # let tampon = Buffer.create 80 ;;
> val tampon : Buffer.t = <abstr>
> #  let canal = new Netchannels.output_buffer tampon in
>    Nethtml.write canal [page] ; print_string (tampon.contents);;

                                                ^^^^^^^^^^^^^^^^

Replace this with: Buffer.contents tampon

".contents" is a legal expression for references, e.g.

let x = ref 42 ;;
print_int x.contents ;;

Because of this the compiler thinks tampon is a reference, and this
explains the error message you get.

Gerd

> This expression has type Buffer.t but is here used with type 'a ref
> 
> 
> "tampon" is the underlined word.
> What I expected is to have 
> 
> <body>rien</body>
> 
> displayed.
> 
> Thank you for your help...
> 
-- 
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany 
[email protected]          http://www.gerd-stolpmann.de
------------------------------------------------------------




-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7412&alloc_id=16344&op=click