最佳答案
Haskell 的类型安全是仅次于依赖类型语言的 一个也没有。但是 短信,打印有一些深层次的魔力,看起来相当不靠谱。
> printf "%d\n" 3
3
> printf "%s %f %d" "foo" 3.3 3
foo 3.3 3
这背后的深层魔力是什么? Text.Printf.printf
函数如何能够接受这样的可变参数?
在哈斯克尔,用什么样的一般技巧来考虑可变论点? 它是如何起作用的?
(附注: 使用这种技术时,显然会丧失某种类型的安全性。)
> :t printf "%d\n" "foo"
printf "%d\n" "foo" :: (PrintfType ([Char] -> t)) => t