Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Christophe TROESTLER <debian00@tiscali.be>
To: "O'Caml Mailing List" <caml-list@inria.fr>
Subject: [Caml-list] Polymorphic pretty printer
Date: Sat, 28 Feb 2004 20:00:07 +0100 (CET)	[thread overview]
Message-ID: <20040228.200007.98389863.debian00@tiscali.be> (raw)

Hi,

I am trying to create a pretty printer (PP) for a polymorphic data
structure.  The problem is to delegate the printing of the polymorphic
values to the default PP of the toploop.  My best try so far is (on a
boiled down example):

type 'a exp = A of 'a

open Outcometree

let print_out_value_orig = !Toploop.print_out_value

let rec print_out_value ppf = function
  | Oval_constr(Oide_ident(name), [params]) when name = "A" ->
      Format.fprintf ppf "@[<2>(|%a|)@]" print_out_value params
  | tree -> print_out_value_orig ppf tree

let () =
  Toploop.print_out_value := print_out_value

This seems to work

# A (A 3);;
- : int exp exp = (|(|3|)|)

but of course does not because the recursive calls inside
print_out_value_orig call print_out_value_orig and
not !Toploop.print_out_value.  Thus

# [ A 3 ];;
- : int exp list = [A 3]

Also the above code is not so nice as it requires to check for the A
structure manually while this is not necessary with #install_printer.

Any help to solve this problem will be greatly appreciated (I do not
want to copy oprint.ml and modify it).  Maybe a third parameter to the
function passed to #install_printer that would handle the rec call is
all that is needed -- so it would be enough to write something like

let print_exp print ppf (A a) =
  Format.fprintf ppf "@[<2>(|@%a|)@]" print a

#install_printer print_exp;;

Is something like this possible ???


Thanks,
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


                 reply	other threads:[~2004-02-28 18:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20040228.200007.98389863.debian00@tiscali.be \
    --to=debian00@tiscali.be \
    --cc=caml-list@inria.fr \
    /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