2014-07-17 19 views
1

我有一个函数,它使用了Dot运算符。现在我想写它没有点。我怎样才能做到这一点?haskell中的点算子

all p = and . map p 

这是正确的吗?

all p = and (map p) 

我得到这些错误:

4.hs:8:13: 
    Couldn't match expected type `[Bool]' 
       with actual type `[a0] -> [b0]' 
    In the return type of a call of `map' 
    Probable cause: `map' is applied to too few arguments 
    In the first argument of `and', namely `(map p)' 
    In the expression: and (map p) 

回答

14

看:

f . g = \ x -> f (g x) 

扩大这给

and . (map p) = \x -> and ((map p) x) 

all p x = and (map p x) 
4

删除(.)需要明确地加入论点,即点是“线程”通过你的功能。你想在definition(.)的类似

all p xs = and (map p xs) 
+1

“埃塔扩张” –