[Haskell-beginners] Function composition with more than 1 parameter

Chry Cheng chrycheng at gmail.com
Sat Oct 25 08:57:50 EDT 2008


Glurk <streborg at hotmail.com> writes:

> Type error in application
> *** Expression     : length . matches
> *** Term           : length
> *** Type           : [b] -> Int
> *** Does not match : ([a] -> [a]) -> Int
>
> Which I can't quite make out what it means.
> Ok, it's telling me lengt has a type [b] -> Int which makes sense,
> but it says it expected a different type, ([a] -> [a]) -> Int
> What I can't understand is why it wants something of that type ?

It's not saying that it wants ([a] -> [a]) -> Int.  Rather, it's saying
that the type it inferred (([a] -> [a]) -> Int) is not what it wants
([b] -> Int).  It expected that a list would be passed to length ([b]).
Instead, you pass a function that eats and spews strings ([a] -> [a])
which is the type that matches would have after being partially applied
(e.g., matches 'e').

> Is it possibly something to do with the higher precedence of function 
> application over function composition ?

I don't think so.  You might be confusing the instances of length and
matches in your new definition of howMany as function applications.  In
it, the only function that is getting applied is . which is passed
length and matches as arguments.


More information about the Beginners mailing list