我在几篇文章和博客中看到了对curried函数的引用,但我找不到一个好的解释(或者至少有一个有意义的解释!)
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) 在python zip
函数中接受任意数量的列表并将它们拉到一起.
>>> l1 = [1,2,3]
>>> l2 = [5,6,7]
>>> l3 = [7,4,8]
>>> zip(l1,l2,l3)
[(1, 5, 7), (2, 6, 4), (3, 7, 8)]
>>>
Run Code Online (Sandbox Code Playgroud)
我如何zip
在haskell中组合多个列表?
我在基本的Haskell库中找到了这个文档:
zip :: [a] -> [b] -> [(a, b)]
zip takes two lists and returns a list of corresponding pairs. If one input list is short, excess elements of the longer list are discarded.
zip3 :: [a] -> [b] -> [c] -> [(a, b, c)]
zip3 takes three lists and returns a list of triples, analogous to zip.
zip4 :: [a] -> [b] -> [c] -> [d] -> [(a, b, c, d)]
The zip4 function takes four lists and returns …
Run Code Online (Sandbox Code Playgroud)