Reputation: 667
I defined function listToNumber as below:
listToNumber = foldl1 (\acc xs -> acc*10 + xs)
It works fine when only supplied with one numeric list, for example:
listToNumber [1,2,3,4] = 1234
map listToNumber [[1,2,3,4], [5,4,3,2]] = [1234,5432]
However, the following returns error message:
map listToNumber permutations[1..3]
can someone explain please?
P.S. the error msg is as below:
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]
Upvotes: 3
Views: 379
Reputation: 2013
try map listToNumber (permutations [1 .. 3])
in ghci you can check the type of a function or an expression with :t
> :t map
> map :: (a -> b) -> [a] -> [b]
im means map
requires a function and a list and returns a list, but in map listToNumber permutations [1 .. 3]
you try to pass two functions and a list to map
(since function application associates to the left).
Upvotes: 7