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 BAA05375; Wed, 1 May 2002 01:30:23 +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 BAA05371 for ; Wed, 1 May 2002 01:30:22 +0200 (MET DST) Received: from tkb.mpl.com ([66.109.164.210]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g3UNUL527564 for ; Wed, 1 May 2002 01:30:21 +0200 (MET DST) Received: from tkb.mpl.com (tkb.mpl.com [66.109.164.210]) by tkb.mpl.com (8.11.6/8.11.6) with ESMTP id g3UNUI933990; Tue, 30 Apr 2002 19:30:19 -0400 (EDT) (envelope-from tkb@tkb.mpl.com) From: "T. Kurt Bond" MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15567.10506.485221.250816@tkb.mpl.com> Date: Tue, 30 Apr 2002 19:30:18 -0400 To: caml-list@inria.fr Subject: [Caml-list] Danvy "Functional Unparsing" style output in OCaml [was: How to read three integers from a text-file... ?] In-Reply-To: <20020429084410.A3490@pauillac.inria.fr> References: <15557.14957.358556.545541@absurd.mimuw.edu.pl> <20020424212316.GA26318@cs.net.pl> <20020429084410.A3490@pauillac.inria.fr> X-Mailer: VM 7.00 under Emacs 21.2.1 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Francois Pottier writes: > Check out Olivier Danvy's paper `Functional Unparsing': > > http://www.brics.dk/RS/98/12/ > > It describes a very nice way of programming `printf' within ML's type > system. `scanf' could be handled in a similar way. Furthermore, this approach > yields code that is claimed to be more efficient than O'Caml's current > `printf' implementation (because the overhead of interpreting format strings > is lower). Lastly, it scales up to more expressive format directives, such as > a directive for printing a list. > > It might be worth adding a module that implements Danvy-style `printf' and > `scanf' to the standard library. Has anyone written such a module already? > Otherwise, I might consider doing it. Back during an earlier discussion of Danvy-style output (probably on this) I implemented a simple module for this (possibly starting from some code that flew by on the list). This round of discussion prompted me to go back and finish it up and knock of a few of the rough edges and package it up. Here's the README: Cpsio is an Objective Caml implementation of the continuation-passing-style output from Olivier Danvy's paper Functional Unparsing. It is available from: http://tkb.mpl.com/~tkb/software.html The distribution is a gzipped tar file. It includes two modules: + Cpsio, which has a format function comparable to sprintf; and + Cpsio_exp, which has format_string, format_out, and format_err functions comparable to sprintf, printf, and eprintf, and a format function that allows the user to specify an accumulator/output function and an initial value (the later function is used to build the three previous functions and is available to clients for use with client-defined accumualtor/output functions). Both modules have (rough) Ocamldoc documentation. The distribution also includes test/example/benchmark programs for both Cpsio and Cpsio_exp, and benchmark programs for comparing against OCaml and C printf-style output. Perfomance with the bytecode compiler mostly seems slightly faster than the OCaml printf, while performance with the native code compiler seems to range from slower than the OCaml printf to barely faster than the OCaml printf. Deficiencies + Despite the "io" in the name, it unfortunately does not include input at this time, just output. + The Makefile is weak and does not have an install target. I do not claim that this code is most elegant or most efficent implementation of this idea. I would welcome comments on the code. This software is in the public domain. -- T. Kurt Bond, tkb@tkb.mpl.com ------------------- 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