[Haskell-cafe] Re: Pure Haskell Printf

Keean Schupke k.schupke at imperial.ac.uk
Tue Nov 16 06:29:37 EST 2004


Actually it can be statically checked, as the string is a constant, we can
lift it to a type (at the moment we would have to use template haskell - but
there is no reason the compiler cannot be a little more aggresive in 
applying
functions to constants at compile time, in which case we can use 
polymorphic
recursion)... So the format string can be lifted to something like:

format :: HCons (ConstString (HCons ParString (HCons ParInt HNil)))

we can then construct a class to recurse on this type checking each of the
'Par...' types against the argument to ensure the type is correct. The code
would look like Oleg's variable argument function code with an additional
class parameter for the format-type.

    Keean.

Henning Thielemann wrote:

>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.
>
>
>_______________________________________________
>Haskell-Cafe mailing list
>Haskell-Cafe at haskell.org
>http://www.haskell.org/mailman/listinfo/haskell-cafe
>  
>



More information about the Haskell-Cafe mailing list