[Haskell-cafe] Re: Pure Haskell Printf
jgoerzen at complete.org
Tue Nov 16 09:47:16 EST 2004
On 2004-11-16, Jon Fairbairn <Jon.Fairbairn at cl.cam.ac.uk> wrote:
> On 2004-11-16 at 11:42+0100 Peter Simons wrote:
>> I'm not sure, though, whether this is the case here, because
>> vsnprintf in Haskell still is type-safe.
> Not statically, though, surely?
>> vsprintf "%d, your age is %s\n" "John" (10::Integer)
> is type incorrect, but won't be reported at compile time. At
> least I can't see how it could be, given that the string
> can't be dissected at compile time.
You are correct. One of the drawbacks of doing this in pure Haskell is
that you lose compile-time type checking. The above code will throw an
exception at runtime.
Ian Lynagh's Template Haskell-based Printf doesn't suffer from that
problem, since it can generate the appropriate Haskell code at compile
time. On the other hand, it is less portable. So not all printf
implementations for Haskell have this problem.
So, people have an option. That's my intent.
More information about the Haskell-Cafe