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 に答える