
On 23 November 2004 20:34, Lennart Augustsson wrote:
Being an old C programmer I'd like to suggest a library, Text.Printf, for C printf() style formatting.
For example
do printf "Hello, world\n" printf "%s, cruel %s\n" "Goodbye" "world" printf "pi is about %10.8f\n" (pi::Double)
I have a Haskell 98 implementation of this function if people feel that it would be useful.
I'd like to pull this in, or something like it. IMHO, the lack of static type safety is outweighed by the shear convenience, and it's too small to provide as a separate library. It'd be nice to have hPrintf :: (PrintfType a) -> Handle -> String -> a too. Cheers, Simon

On 2004-11-24, Simon Marlow
On 23 November 2004 20:34, Lennart Augustsson wrote: I'd like to pull this in, or something like it. IMHO, the lack of static type safety is outweighed by the shear convenience, and it's too small to provide as a separate library.
It'd be nice to have
hPrintf :: (PrintfType a) -> Handle -> String -> a
Don't forget sprintf, though I haven't yet studied this code enough to figure out how to do it with this model. sprintf could and should be a pure function that can be executed outside the IO monad. Quite useful for, say, internals of a string generation routine. -- John

My printf was a sprintf too. I.e., the return value could be eoither `IO a' or String. Easy to implement, but probably confusing. :) -- Lennart John Goerzen wrote:
On 2004-11-24, Simon Marlow
wrote: On 23 November 2004 20:34, Lennart Augustsson wrote: I'd like to pull this in, or something like it. IMHO, the lack of static type safety is outweighed by the shear convenience, and it's too small to provide as a separate library.
It'd be nice to have
hPrintf :: (PrintfType a) -> Handle -> String -> a
Don't forget sprintf, though I haven't yet studied this code enough to figure out how to do it with this model.
sprintf could and should be a pure function that can be executed outside the IO monad. Quite useful for, say, internals of a string generation routine.
-- John
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

At 09:05 25/11/04 +0100, Lennart Augustsson wrote:
My printf was a sprintf too. I.e., the return value could be eoither `IO a' or String. Easy to implement, but probably confusing. :)
I noticed that. I don't yet fully understand how it all works, but it did strike me as very neat. I think this could prove to be one of those programming examples that deserves wider distribution and study if only for what it can teach about programming in Haskell. I, too, would like to see it in the common libraries. #g ------------ Graham Klyne For email: http://www.ninebynine.org/#Contact

-----Original Message----- From: libraries-bounces@haskell.org [mailto:libraries-bounces@haskell.org] On Behalf Of Graham Klyne Sent: den 25 november 2004 13:29 To: Lennart Augustsson Cc: libraries@haskell.org Subject: Re: printf
At 09:05 25/11/04 +0100, Lennart Augustsson wrote:
My printf was a sprintf too. I.e., the return value could be eoither `IO a' or String. Easy to implement, but probably confusing. :)
I noticed that. I don't yet fully understand how it all works, but it did strike me as very neat.
The trick Lennart is using is indeed neat. But afaIct it is not known to most Haskell hackers. It deserves better attention. Another library which uses this kind of trick is Björn Bringert's XML-RPC library: http://www.dtek.chalmers.se/~d00bring/haskell-xml-rpc/ Cheers, /Josef
participants (5)
-
Graham Klyne
-
John Goerzen
-
Josef Svenningsson
-
Lennart Augustsson
-
Simon Marlow