Haskell printf如何工作? - How does Haskell printf work?

问题:

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

解决方案:

参考: https://stackoom.com/en/question/WqRE
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章