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 AAA09141; Sat, 23 Oct 2004 00:07:32 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA09341 for ; Sat, 23 Oct 2004 00:07:30 +0200 (MET DST) Received: from mailfe08.swip.net (mailfe08.swip.net [212.247.154.225]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id i9MM7Uv1000902 for ; Sat, 23 Oct 2004 00:07:30 +0200 X-T2-Posting-ID: 2IIuXFmkcTpj3lKEFKW25A== Received: from [83.176.175.135] (HELO poincare) by mailfe08.swip.net (CommuniGate Pro SMTP 4.2.4) with ESMTP id 4039069; Sat, 23 Oct 2004 00:07:29 +0200 Received: from poincare ([127.0.0.1] helo=localhost ident=trch) by poincare with esmtp (Exim 3.36 #1 (Debian)) id 1CL7ZC-00025g-00; Sat, 23 Oct 2004 00:07:22 +0200 Date: Sat, 23 Oct 2004 00:07:11 +0200 (CEST) Message-Id: <20041023.000711.91476428.debian00@tiscali.be> To: Andrej.Bauer@andrej.com Cc: "O'Caml Mailing List" Subject: Re: [Caml-list] Polymorphic pretty printing From: Christophe TROESTLER In-Reply-To: <4173E464.7030500@andrej.com> References: <4173E464.7030500@andrej.com> Organization: None X-Spook: brigand S Key hackers Uzi Audiotel Honduras Roswell ISEC bluebird afsatcom X-Blessing: Om Ah Hum Vajra Guru Pema Siddhi Hum X-Operating-System: GNU/Linux (http://www.linux.org/) X-Mailer-URL: http://www.mew.org/ X-Mailer: Mew version 4.1 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 417984A2.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 troestler:01 tiscali:99 andrej:01 bauer:01 andrej:01 bauer:01 outcometree:01 outcometree:01 toploop:01 fprintf:01 toploop:01 chris:01 christophe:01 caml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, 18 Oct 2004, Andrej Bauer 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