From: "Frédéric Gava" <frederic.gava@wanadoo.fr>
To: <Andrej.Bauer@andrej.com>, "Christophe TROESTLER" <debian00@tiscali.be>
Cc: "O'Caml Mailing List" <caml-list@inria.fr>
Subject: Re: [Caml-list] Polymorphic pretty printing
Date: Fri, 26 Nov 2004 23:54:27 +0100 [thread overview]
Message-ID: <017d01c4d40a$e2550280$0cfa3151@mshome.net> (raw)
In-Reply-To: <20041023.000711.91476428.debian00@tiscali.be>
Hi, I have test and it is possible.
Daniel de Rauglaudre wrote in
>From: Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr>
>Date: Fri, 25 Jan 2002 06:58:14 +0100
"Another example is the "revised syntax" of Camlp4 in the OCaml
sources, file "camlp4/top/rprint.ml". (use "camlp4r pr_o.cmo
camlp4/top/rprint.ml" to see this file in normal syntax, if you
prefer). "
Take the function "print_out_value" of camlp4r pr_o.cmo
camlp4/top/rprint.ml" , modify it (it is easy, the code is very clear) for
your application and
run : Toploop.print_out_value := print_out_value.
Do not forget do modify "True" to "true" (idem for "False") to have a
correct printing of Ocaml values.
I have
type 'a vec = Vector of 'a array
and I modify 'print_out_value" to print vector as <...,...,...> and
(Vector (Array.init 3 (fun i->i)), Vector (Array.init 3 (fun i->i))) prints
(<0,1,2>, <0,1,2>) without problem and I do not have modify at all the
toplevel.
Cheers,
Frédéric Gava
>----- Original Message -----
>From: "Christophe TROESTLER" <debian00@tiscali.be>
>To: <Andrej.Bauer@andrej.com>
>Cc: "O'Caml Mailing List" <caml-list@inria.fr>
>Sent: Friday, October 22, 2004 11:07 PM
>Subject: Re: [Caml-list] Polymorphic pretty printing
> On Mon, 18 Oct 2004, Andrej Bauer <Andrej.Bauer@andrej.com> wrote:
> >
> > how to install a pretty printer for a _polymorphic_ type.
> > http://caml.inria.fr/archives/200201/msg00234.html
> >
> > I should use Toplevel.print_out_value to do this. But,
> > print_out_value expects an arguments of type Outcometree.out_value,
> > and it is not clear to me where I will get it.
>
> Since you will register a new printing function, you will not have to
> get it, Outcometree.out_value will be provided to your function! To
> get you a flavor of how (I understand) it works, here is some code:
>
> let oldpp = !Toploop.print_out_value
> let pp f o =
> (match o with
> | Outcometree.Oval_list _ ->
> Format.fprintf f "list:"
> | _ -> ());
> oldpp f o
> Toploop.print_out_value := pp
>
> Now, a list is written as
>
> # [1;2];;
> - : int list = list:[1; 2]
>
> > Am I supposed to rewrite half of toplevel.ml to get this working?
>
> I am afraid that the awser is yes :(. Let's see why:
>
> # ([1; 2], 2);;
> - : int list * int = ([1; 2], 2)
>
> Now the above [pp] pretty printer is registered but it does not to
> work. This is because the original function registered in
> [Toploop.print_out_value] is recursive instead of calling
> [!Toploop.print_out_value] (there is certainly a reason but I do not
> know it) -- thus since the "top" structure is a couple, [oldpp] is
> called and never calls back [pp].
>
> Therefore, not only we have to duplicate all the code of the original
> [!Toploop.print_out_value] (and check conformance at every upgrade)
> but that also means it is difficult for several polymorphic pretty
> printers to cooperate.
>
> This is really unfortunate as this prevents libraries to use
> [Sys.interactive] in order to install pretty printers for their
> polymorphic types.
>
> Hope a nice solution can be designed for this last usage.
>
> Cheers,
> ChriS
>
> -------------------
> 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
prev parent reply other threads:[~2004-11-26 22:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-18 15:42 Andrej Bauer
2004-10-22 22:07 ` Christophe TROESTLER
2004-10-24 20:54 ` Andrej Bauer
2004-10-25 1:04 ` skaller
2004-10-25 3:02 ` David Brown
2004-10-25 7:26 ` Andrej Bauer
2004-10-25 14:45 ` Jon Harrop
2004-11-26 22:54 ` Frédéric Gava [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='017d01c4d40a$e2550280$0cfa3151@mshome.net' \
--to=frederic.gava@wanadoo.fr \
--cc=Andrej.Bauer@andrej.com \
--cc=caml-list@inria.fr \
--cc=debian00@tiscali.be \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox