3 ms·
> the types required to apply the function are statically analyzed from the format string. Not so, in that Haskell package: Prelude Text.Printf> printf "%
by dllthomas 9y ago
> the types required to apply the function are statically analyzed from the format string.
Not so, in that Haskell package:
Prelude Text.Printf> printf "%d\n" 1
1
Prelude Text.Printf> printf "%d\n"
*** Exception: printf: argument list ended prematurely
Prelude Text.Printf> printf "%d\n" 0.5
*** Exception: printf: bad formatting char 'd'
Prelude Text.Printf> printf "%d\n" 1 2
1
*** Exception: printf: formatting string ended prematurely
It could certainly be done with TH/QQ. I'm not sure, offhand, if there is already a package to that effect.
- hesselink 9y agoThere are several packages on hackage offering a type safe printf. Some use TH, some use variadic functions (defined with a type class) or other advanced type level features.
- dllthomas 9y agoVariadic functions are used in the package under discussion, and don't get you compile time checking of the format string.