Haskell的类型安全性仅对于依赖类型的语言是首屈一指的.但是Text.Printf有一些深刻的魔力似乎相当类型.
> printf "%d\n" 3
3
> printf "%s %f %d" "foo" 3.3 3
foo 3.3 3
Run Code Online (Sandbox Code Playgroud)
这背后的深层魔力是什么?该Text.Printf.printf函数如何采用像这样的可变参数?
用于允许Haskell中的可变参数的一般技术是什么,它是如何工作的?
(旁注:使用这种技术时,某种类型的安全性显然会丢失.)
> :t printf "%d\n" "foo"
printf "%d\n" "foo" :: (PrintfType ([Char] -> t)) => t
Run Code Online (Sandbox Code Playgroud)