Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "T. Kurt Bond" <tkb@tkb.mpl.com>
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... ?]
Date: Tue, 30 Apr 2002 19:30:18 -0400	[thread overview]
Message-ID: <15567.10506.485221.250816@tkb.mpl.com> (raw)
In-Reply-To: <20020429084410.A3490@pauillac.inria.fr>

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


  parent reply	other threads:[~2002-04-30 23:30 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-23 10:41 [Caml-list] How to read three integers from a text-file... ? Jacek Chrzaszcz
2002-04-24 10:44 ` Stefano Lanzavecchia
2002-04-24 18:46   ` Tomasz Zielonka
2002-04-24 11:16 ` Jacques Garrigue
2002-04-24 13:40   ` Tomasz Zielonka
2002-04-25  5:30   ` pervasives (was: Re: [Caml-list] How to read three integers from a text-file... ?) Chris Hecker
2002-04-25  6:33     ` Tomasz Zielonka
2002-04-25 17:54       ` Chris Hecker
2002-04-27  4:43         ` John Max Skaller
2002-04-27 16:02           ` [Caml-list] input_line (Re: pervasives) Lauri Alanko
2002-04-30 12:07             ` [Caml-list] input_line Xavier Leroy
2002-05-03  0:13               ` Lauri Alanko
2002-05-03 11:27                 ` Florian Hars
2002-04-24 21:23 ` [Caml-list] How to read three integers from a text-file... ? Tomasz Zielonka
2002-04-25  1:51   ` John Max Skaller
2002-04-25  8:55   ` Daniel de Rauglaudre
2002-04-25 11:19     ` Markus Mottl
2002-04-25 11:33       ` Jérôme Marant
2002-04-25 11:43         ` Markus Mottl
2002-04-25 17:56         ` Chris Hecker
2002-04-25 20:52           ` John Prevost
2002-04-25 23:32           ` Jacques Garrigue
2002-04-26  7:25             ` Jérôme Marant
2002-04-26 12:16           ` Jacques Garrigue
2002-05-02  8:48             ` Jacques Garrigue
2002-04-26  1:39         ` Daniel de Rauglaudre
2002-04-29  6:44   ` Francois Pottier
2002-04-30 11:07     ` Dave Berry
2002-04-30 12:20       ` Francois Pottier
2002-04-30 13:54         ` T. Kurt Bond
2002-05-03 22:12         ` Dave Berry
2002-04-30 14:42       ` Jocelyn Sérot
2002-05-02  7:34         ` [Caml-list] Extensible tuple types Francois Pottier
2002-05-02  9:42           ` Alain Frisch
2002-05-02 11:03             ` Francois Pottier
     [not found]       ` <6ECF4649-5C48-11D6-AC27-0003934491C2@lasmea.univ-bpclermon t.fr>
2002-05-03 21:58         ` [Caml-list] How to read three integers from a text-file... ? Dave Berry
2002-05-06  0:53           ` Eray Ozkural
2002-05-06  6:40           ` Florian Hars
2002-04-30 23:30     ` T. Kurt Bond [this message]
2002-05-13 14:11       ` [Caml-list] RE: Danvy "Functional Unparsing" style output in OCaml T. Kurt Bond
2002-05-13 19:59         ` [Caml-list] "Functional Unparsing" benchmark results links fixed [Was: Danvy "Functional Unparsing" style output in OCaml] T. Kurt Bond

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15567.10506.485221.250816@tkb.mpl.com \
    --to=tkb@tkb.mpl.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox