2014-07-17 48 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

「埃塔擴張」 –