From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 513AABC2F for ; Fri, 26 Nov 2004 23:53:18 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id iAQMrHlV021517 for ; Fri, 26 Nov 2004 23:53:17 +0100 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 XAA25218 for ; Fri, 26 Nov 2004 23:53:16 +0100 (MET) Received: from smtp2.wanadoo.fr (smtp2.wanadoo.fr [193.252.22.29]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id iAQMrFsM010395 for ; Fri, 26 Nov 2004 23:53:16 +0100 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf0202.wanadoo.fr (SMTP Server) with SMTP id CF6DA1C00205; Fri, 26 Nov 2004 23:53:15 +0100 (CET) Received: from nono (ARouen-106-1-19-12.w81-49.abo.wanadoo.fr [81.49.250.12]) by mwinf0202.wanadoo.fr (SMTP Server) with SMTP id 4FDFE1C00207; Fri, 26 Nov 2004 23:53:15 +0100 (CET) Message-ID: <017d01c4d40a$e2550280$0cfa3151@mshome.net> From: =?iso-8859-1?Q?Fr=E9d=E9ric_Gava?= To: , "Christophe TROESTLER" Cc: "O'Caml Mailing List" References: <4173E464.7030500@andrej.com> <20041023.000711.91476428.debian00@tiscali.be> Subject: Re: [Caml-list] Polymorphic pretty printing Date: Fri, 26 Nov 2004 23:54:27 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Miltered: at concorde with ID 41A7B3DD.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 41A7B3DB.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; gava:01 gava:01 caml-list:01 rauglaudre:01 wrote:01 rauglaudre:01 syntax:01 ocaml:01 rprint:01 cmo:01 rprint:01 syntax:01 cmo:01 toploop:01 idem:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: Hi, I have test and it is possible. Daniel de Rauglaudre wrote in >From: Daniel de Rauglaudre >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" >To: >Cc: "O'Caml Mailing List" >Sent: Friday, October 22, 2004 11:07 PM >Subject: Re: [Caml-list] Polymorphic pretty printing > 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