caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe Filliatre <filliatr@lri.fr>
To: Alessandro Baretta <a.baretta@barettadeit.com>
Cc: Ocaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Request for comments: Printf list conversion
Date: Thu, 12 Jan 2006 10:55:56 +0100	[thread overview]
Message-ID: <17350.10156.454589.275252@gargle.gargle.HOWL> (raw)
In-Reply-To: <43C61F1F.4030101@barettadeit.com>


Hello,

Alessandro Baretta writes:
 > I would like to transform the following rather vague idea into a
 > formal feature  
 > request. Before doing this, I would like to know what others think about it.
 > 
 > I continually come across the need to pretty-print via Printf a list of 
 > values--for example, let's say an int list. 

I recently submitted a similar wish on the bug tracking system, which
is slightly more general than your proposal:

  http://caml.inria.fr/mantis/view.php?id=3882

Meanwhile, I'm using a rather different solution than yours, that is a
custom function

  val print_list : (formatter -> 'a -> unit) -> formatter -> 'a list -> unit

that I use with %a, e.g.

  fprintf fmt "this is the list %a" (print_list pp_print_int) [1;2;3]

I  actually use a  more general  version of  print_list that  allows a
separator  to  be  specified  (to  be  printed  in  between  the  list
elements):

  val print_list : 
    ?sep:(formatter -> unit -> unit) -> 
    (formatter -> 'a -> unit) -> formatter -> 'a list -> unit

which comes with a handy list of predefined separators:

  val space : formatter -> unit -> unit
  val newline : formatter -> unit -> unit
  val comma : formatter -> unit -> unit
  val semi : formatter -> unit -> unit
  val nothing : formatter -> unit -> unit
  etc.

Hope this helps,
-- 
Jean-Christophe Filliâtre (http://www.lri.fr/~filliatr)


  parent reply	other threads:[~2006-01-12  9:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-12  9:19 Alessandro Baretta
2006-01-12  9:31 ` [Caml-list] " Jean-Marc EBER
2006-01-12  9:55 ` Jean-Christophe Filliatre [this message]
2006-01-12 12:55   ` Damien Doligez
2006-01-12 13:27     ` Virgile Prevosto
2006-01-13  8:47       ` Jean-Christophe Filliatre
2006-01-12 15:50 ` Bill Wood
2006-01-12 17:39   ` Richard Jones
2006-01-12 19:29     ` Bill Wood
2006-01-13  9:31   ` Hendrik Tews
2006-01-13 16:28     ` Bill Wood

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=17350.10156.454589.275252@gargle.gargle.HOWL \
    --to=filliatr@lri.fr \
    --cc=a.baretta@barettadeit.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;
as well as URLs for NNTP newsgroup(s).