1

我有一个使用点运算符的函数。现在我想写没有点。我怎样才能做到这一点?

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)
4

2 回答 2

14

看看的定义(.)

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

扩展这给出

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

或者

all p x  =  and (map p x)
于 2014-07-17T10:51:25.770 回答
4

删除(.)需要明确添加点是通过您的函数“穿线”的参数。你想要类似的东西

all p xs = and (map p xs)
于 2014-07-17T10:50:11.860 回答