問題:
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