[Haskell-cafe] Re: Pure Haskell Printf

Henning Thielemann iakd0 at clusterf.urz.uni-halle.de
Tue Nov 16 06:21:41 EST 2004


On 16 Nov 2004, Peter Simons wrote:

> I'm not sure, though, whether this is the case here, because
> vsnprintf in Haskell still is type-safe. You'll get more
> complicated error messages, the memory footprint might be
> worse, but it still _is_ robust code.

Yes and no. It can't be checked statically if the number of placeholders
matches the number of arguments. It can't be checked statically if the
types of placeholders match the types of arguments. It is not possible to
create functions with more than one variable length parameter lists.

>   Dear ${customer},
> 
>   are you interested in making ${phantasy-number} fast?
> 
> and pass a function (String -> a) to vsnprintf which does
> the lookup. I'm not sure how having different types of
> values in the dictionary plays into this, though.

The function MissingH.Printf.sprintf is probably the better choice, but
one could even replace [Value] by [String]. The conversion from any type
to String can be easily done using 'show' by the caller. Though it gives
the author of the format string less control over the formatting of
particular types like numbers.




More information about the Haskell-Cafe mailing list