From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] OCaml's formatting libraries
Date: Sat, 10 Nov 2007 19:13:14 +0000 [thread overview]
Message-ID: <200711101913.14541.jon@ffconsultancy.com> (raw)
In-Reply-To: <B68E6127-94F7-4C42-8D6C-EE613E99E47E@erratique.ch>
On Saturday 10 November 2007 15:43, Bünzli Daniel wrote:
> Le 10 nov. 07 à 15:58, Jon Harrop a écrit :
> > Functional unparsing requires a lot more code,
>
> It's a little bit less concise but I wouldn't say it is a *lot*.
printf "%25s %d\n%25s %g\n%25s %s\n\n%25s ]%*d[\n%25s ]%*d[\n\
%25s ]%*g[\n%25s ]%*g[\n%25s ]%*s[\n%25s ]%*s[\n"
"int:" 10 "float:" 1.234 "string:" "foo"
"int with width:" 20 24 "int with -width:" (-20) 42
"float with width:" 20 1.234 "float with -width:" (-20) 567.8
"string with width:" 20 "Hello"
"string with -width:" (-20) "Goodbye"
vs:
print_string
(format
(wlit "int:" 25 $ lit " " $ int $ nl $
wlit "float:" 25 $ lit " " $ flt $ nl $
wlit "string:" 25 $ lit " " $ str $ nnl 2 $
wlit "int with width:" 25 $ lit " ]" $ intw $ lit "[" $ nl $
wlit "int with -width:" 25 $ lit " ]" $ intw $ lit "[" $ nl $
wlit "float with width:" 25 $ lit " ]" $ fltw $ lit "[" $ nl $
wlit "float with -width:" 25 $ lit " ]" $ fltw $ lit "[" $ nl $
wlit "string with width:" 25 $ lit " ]" $ strw $ lit "[" $ nl $
wlit "string with -width:" 25 $ lit " ]" $ strw $ lit "[" $ nl )
()
10 1.234 "foo" (* int, float, string *)
24 20 42 (-20) (* int with width, -width spec *)
1.234 20 567.8 (-20) (* float with width, -width spec *)
"Hello" 20 (* string with width spec *)
"Goodbye" (-20) (* string with -width spec *)
)
> > produces worse error messages,
>
> Example please.
Oops, I forgot one of the 36 superfluous "$" operators. OCaml now fails to
catch my trivial (but likely) mistake and now my program produces incorrect
output and the patient dies on the table whilst gurgling out "should've spent
less time proving correctness and more time testing":
# let test1 () =
print_string
(format
(wlit "int:" 25 $ lit " " $ int $ nl $
wlit "float:" 25 $ lit " " $ flt $ nl $
wlit "string:" 25 $ lit " " $ str $ nnl 2 $
wlit "int with width:" 25 $ lit " ]" $ intw $ lit "[" $ nl
wlit "int with -width:" 25 $ lit " ]" $ intw $ lit "[" $ nl $
wlit "float with width:" 25 $ lit " ]" $ fltw $ lit "[" $ nl $
wlit "float with -width:" 25 $ lit " ]" $ fltw $ lit "[" $ nl $
wlit "string with width:" 25 $ lit " ]" $ strw $ lit "[" $ nl $
wlit "string with -width:" 25 $ lit " ]" $ strw $ lit "[" $ nl )
()
10 1.234 "foo" (* int, float, string *)
24 20 42 (-20) (* int with width, -width spec *)
1.234 20 567.8 (-20) (* float with width, -width spec *)
"Hello" 20 (* string with width spec *)
"Goodbye" (-20) (* string with -width spec *)
);;
val test1 : unit -> unit = <fun>
# test1();;
int: 10
float: 1.234
string: foo
int with width: ] 24[ int with -width:
]42 [
float with width: ] 1.234[
float with -width: ]567.8 [
string with width: ] Hello[
string with -width: ]Goodbye [
- : unit = ()
> > is much harder to learn,
>
> I don't think so. There really nothing hard in it, it is just ...
> different.
Exactly: how many people have heard of printf and how many have heard of
continuation passing style, let alone functional unparsers?
> > is incompatible with the excellent Format module,
>
> Which wouldn't prevent the design of a new format module.
Sure. But we're an extremely finite-sized community and need to prioritize
where we put our efforts. My vote simply goes to putting effort elsewhere.
> > I'd much rather see effort put into visualization and GUI tools
> > rather than
> > ASCII text tools...
>
> I'd rather have a simple and correct type system.
I'd rather have feature-complete software that works.
In practice, a language implementation will only become robust if it has both
a solid theoretical foundation and a significant user base to test the
implementation. As Knuth said "beware: I have proven it correct but not
tested it".
With the benefit of hindsight, Standard ML put too much emphasis on
theoretical correctness and not enough on practical utility. Consequently,
Standard ML does not enjoy OCaml's popularity, has fewer libraries, no
competitively performant compilers and so on. I would not like to see OCaml
take that route.
In this context, I would have thought that printf is very commonly used but
scanf is not. If scanf is difficult to fix then these features could simply
be removed from it.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?e
next prev parent reply other threads:[~2007-11-10 19:22 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-08 14:17 Search for the smallest possible possible Ocaml segfault Till Varoquaux
2007-11-08 15:00 ` [Caml-list] " Jean-Christophe Filliâtre
2007-11-08 15:17 ` Till Varoquaux
2007-11-08 15:55 ` Adrien
2007-11-08 16:05 ` Alain Frisch
2007-11-08 16:30 ` Feature request (was Re: [Caml-list] Search for the smallest possible possible Ocaml segfault....) Martin Jambon
2007-11-08 18:23 ` Martin Jambon
2007-11-08 16:07 ` [Caml-list] Search for the smallest possible possible Ocaml segfault Jeremy Yallop
2007-11-08 16:11 ` Jeremy Yallop
2007-11-08 16:17 ` Till Varoquaux
2007-11-08 17:02 ` Stefano Zacchiroli
2007-11-08 17:10 ` Till Varoquaux
2007-11-08 17:02 ` Pascal Zimmer
2007-11-08 17:12 ` Oliver Bandel
2007-11-08 17:11 ` Oliver Bandel
2007-11-08 17:13 ` Zheng Li
2007-11-08 17:55 ` [Caml-list] STOP (was: Search for the smallest possible possible Ocaml segfault) Xavier Leroy
2007-11-08 18:11 ` Tom Primožič
2007-11-08 18:23 ` [Caml-list] STOP Robert Fischer
2007-11-08 19:01 ` Basile STARYNKEVITCH
2007-11-08 18:31 ` [Caml-list] STOP (was: Search for the smallest possible possible Ocaml segfault) Till Varoquaux
2007-11-08 19:06 ` Oliver Bandel
2007-11-09 18:09 ` Pierre Weis
2007-11-10 14:32 ` OCaml's formatting libraries Bünzli Daniel
2007-11-10 14:58 ` [Caml-list] " Jon Harrop
2007-11-10 15:43 ` Bünzli Daniel
2007-11-10 19:13 ` Jon Harrop [this message]
2007-11-13 9:22 ` Pierre Weis
2007-11-13 9:13 ` Pierre Weis
2007-11-13 8:53 ` Pierre Weis
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=200711101913.14541.jon@ffconsultancy.com \
--to=jon@ffconsultancy.com \
--cc=caml-list@yquem.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