From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA32117; Sat, 28 Feb 2004 19:59:45 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA28626 for ; Sat, 28 Feb 2004 19:59:44 +0100 (MET) Received: from oola.is.scarlet.be (oola.is.scarlet.be [193.74.71.23]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i1SIxnIq019802 for ; Sat, 28 Feb 2004 19:59:49 +0100 Received: from (u212-239-153-150.dialup.planetinternet.be [212.239.153.150]) by oola.is.scarlet.be with ESMTP id i1SIxfo26076; Sat, 28 Feb 2004 19:59:41 +0100 Received: from poincare ([127.0.0.1] helo=localhost ident=trch) by poincare with esmtp (Exim 3.36 #1 (Debian)) id 1Ax9h2-0006Au-00; Sat, 28 Feb 2004 20:00:08 +0100 Date: Sat, 28 Feb 2004 20:00:07 +0100 (CET) Message-Id: <20040228.200007.98389863.debian00@tiscali.be> To: "O'Caml Mailing List" Subject: [Caml-list] Polymorphic pretty printer From: Christophe TROESTLER Organization: None X-Spook: Telex infowar bluebird electronic surveillance $400 million in gold bullion encryption hackers digicash [Hello to all my friends and fans in domestic surveillance] Project Monarch X-Mailer-URL: http://www.mew.org/ X-Operating-System: GNU/Linux (http://www.linux.org/) X-Blessing: Om Ah Hum Vajra Guru Pema Siddhi Hum X-Mailer: Mew version 4.0.61 on Emacs 21.3.1 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; troestler:01 tiscali:99 toploop:01 outcometree:01 toploop:01 constr:01 params:01 fprintf:01 params:01 fprintf:01 chris:01 christophe:01 int:01 int:01 rec:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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