Haskell - 映射函数到置换

use*_*047 3 haskell permutation map

我定义了函数listToNumber如下:

listToNumber = foldl1 (\acc xs -> acc*10 + xs)
Run Code Online (Sandbox Code Playgroud)

只提供一个数字列表时它工作正常,例如:

listToNumber [1,2,3,4] = 1234
map listToNumber [[1,2,3,4], [5,4,3,2]] = [1234,5432]
Run Code Online (Sandbox Code Playgroud)

但是,以下返回错误消息:

map listToNumber permutations[1..3]
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下吗?

PS错误消息如下:

Couldn't match expected type `[t1] -> t0' with actual type `[b0]'
The function `map' is applied to three arguments,
but its type `([b0] -> b0) -> [[b0]] -> [b0]' has only two
In the expression: map listToNumber permutations [1 .. 3]
In an equation for `it':
    it = map listToNumber permutations [1 .. 3]
Run Code Online (Sandbox Code Playgroud)

jev*_*jev 7

尝试 map listToNumber (permutations [1 .. 3])

在ghci中,您可以检查函数的类型或表达式 :t

> :t map
> map :: (a -> b) -> [a] -> [b]
Run Code Online (Sandbox Code Playgroud)

im表示map需要一个函数和一个列表并返回一个列表,但在map listToNumber permutations [1 .. 3]你尝试传递两个函数和一个列表来映射(因为函数应用程序关联到左侧).