Version française
Home     About     Download     Resources     Contact us    
Browse thread
Pervasives 'general output functions'
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas Cannasse <warplayer@f...>
Subject: Re: [Caml-list] Pervasives 'general output functions'
>     Bonjour,
>
> I would like a Caml program to output some information to an output
> channel and according to my needs this channel be redirected to
> - a (human readable) file
> - the standard output
> - a black hole
>
> The "general output functions" section of Pervasives seem to be what I
> need but it hasn't the same signature than "Output functions on
> standard output"

Generic IO from ExtLib are dealing with this problem, and have a printf
functionnality.
They also have useful functions such as  write_i16 / write_ui32 .... (in low
and big endian) when dealing with C binary files.

> I suspect I could just compose with string_of_X functions to obtain
> the same result. There is also an awful [fprintf] function inherided
> from C but I am still trying to understand the doc (never understood
> C's either).

printf "%d %f %s %c"  33 1.234 "hello" 'x'

> Why haven't the equivalent functions been added to the standard lib to
> allow a drop in replacement ?

Maybe because printf allows you to specify precision for int/floats as well
as newlines ?

Nicolas