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 TAA09474; Fri, 15 Oct 2004 19:18:13 +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 TAA09680 for ; Fri, 15 Oct 2004 19:18:12 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from postfix3-2.free.fr (postfix3-2.free.fr [213.228.0.169]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id i9FHICcq027590 for ; Fri, 15 Oct 2004 19:18:12 +0200 Received: from warp (chateaudeau-4-82-225-176-25.fbx.proxad.net [82.225.176.25]) by postfix3-2.free.fr (Postfix) with SMTP id 07FC2C179; Fri, 15 Oct 2004 19:18:11 +0200 (CEST) Message-ID: <001501c4b2db$400492c0$0100a8c0@warp> From: "Nicolas Cannasse" To: , References: <200410151657.i9FGvqt18876@ryxa.irisa.fr> Subject: Re: [Caml-list] a generic print (ugly hack) Date: Fri, 15 Oct 2004 19:20:21 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Miltered: at concorde with ID 41700654.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; cannasse:01 warplayer:01 caml-list:01 generic:01 generic:01 stdout:01 yellow:99 hacks:01 reusing:01 runtime:01 runtime:01 dumped:01 lacks:01 cannasse:01 compiler:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > the goal is to allow the programmer to write in his program for instance: > > let _ = print_string (generic_print [[1;3];[2;9;8];[3;4]] "int list list") in > ... > let _ = print_string (generic_print [1;3;2;9;8;3;4] "int list") in > let v = ... (* big computation, big data structure *) > let _ = print_string (generic_print v "(int * float * color) assoc") in > ... > > > and to get on stdout: > [[1; 3]; [2; 9; 8]; [3; 4]] > [1; 3; 2; 9; 8; 3; 4] > [(1, 2.02, Red); (2, 4.02, Yellow)]; > > > the type of generic_print is > 'a -> string -> string > > code: > http://www.irisa.fr/prive/padiolea/hacks/generic_print.ml > > the principle is that the toplevel of O'Caml know how to print value, > so by "reusing" the toplevel, our program can too. > > > It is slow, ugly, not robust, but it can be helpful. > any suggestion or critics are welcome. I was thinking doing the same some times ago, but without relying on toplevel (which stucks you to bytecode). The idea was to be able to load CMI at runtime, and extract type informations from it in order to correctly print and match types (this is already what's doing ODLL with functions). It's quite a work and I didn't finished it. CMI contains *exact* types informations which are not present at runtime, but not structured in a convenient way for printing or matching since they're directly dumped from the compiler type representation. But once done, this would include some dynamism that ocaml lacks when interacting with outter world (serialization for example). Nicolas Cannasse ------------------- 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