问题:
Haskell's type safety is second to none only to dependently-typed languages. Haskell的类型安全性仅对于依赖类型的语言是首屈一指的 。 But there is some deep magic going on with Text.Printf that seems rather type-wonky. 但是Text.Printf有一些深刻的魔力似乎相当类型。
> printf "%d\n" 3
3
> printf "%s %f %d" "foo" 3.3 3
foo 3.3 3
What is the deep magic behind this? 这背后的深层魔力是什么? How can the Text.Printf.printf
function take variadic arguments like this? Text.Printf.printf
函数如何采用这样的可变参数?
What is the general technique used to allow for variadic arguments in Haskell, and how does it work? 用于允许Haskell中的可变参数的一般技术是什么,它是如何工作的?
(Side note: some type safety is apparently lost when using this technique.) (旁注:使用这种技术时,某种类型的安全性显然会丢失。)
> :t printf "%d\n" "foo"
printf "%d\n" "foo" :: (PrintfType ([Char] -> t)) => t