这个问题与这个Function Composition VS Function Application有关,由antal s-z回答。 你如何得到这个? map has type (a -> b) -> [a] -> [b]
head has type [a] -> a
map head has type [[a]] -> [a]
为什么下面的代码有函数组合的类型错误? test :: [
偶尔我会偶然发现我想表达的问题,“请使用最后一个参数两次”,例如为了写无点式或避免lambda。例如。 sqr x = x * x
可以写成 sqr = doubleArgs (*) where
doubleArgs f x = f x x
或者考虑这个稍微复杂功能(从this question拍摄):如果有类似的功能 ins x xs = zipWith (\ a b -> a
鉴于: data TwoInts = TwoInts Int Int
add'em :: TwoInts -> Int
add'em (TwoInts a b) = a+b
是有可能写add'em,而不必命名a和b。喜欢的东西: add'em TwoInts = (+) -- (Note: Fails to type check)
我编写了下面的代码,它需要一堆点并使用光泽库在屏幕上绘制它们。 let s = blocks pes
pts = map (map mkPt) s {- stitches to points-}
lines = map Line pts {-points to lines -}
pict = Pictures lines {- lines to a picture -