[Haskell-cafe] Re: Very crazy

Andrew Coppin andrewcoppin at btinternet.com
Tue Sep 25 06:55:28 EDT 2007


Chaddaï Fouché wrote:
> 2007/9/25, Andrew Coppin <andrewcoppin at btinternet.com>:
>
>   
>> I just found it rather surprising. Every time *I* try to compose with
>> functions of more than 1 argument, the type checker complains.
>>     
>
> There is no function that takes more than one argument in Haskell. ;-)
> map _could_ be seen as a function with 2 arguments, but in this case
> it's more useful to think of it as a function that take one argument
> f, a function that turn 'a into 'b and turn it into a new function
> that turn a list of 'a into a list of 'b.
>   

This is why I found it so surprising - and annoying - that you can't use 
a 2-argument function in a point-free expression.

For example, "zipWith (*)" expects two arguments, and yet

  sum . zipWith (*)

fails to type-check. You just instead write

  \xs ys -> sum $ zipWith(*) xs ys

which works as expected.

I can't figure out why map . map works, but sum . zipWith (*) doesn't 
work. As I say, the only reason I can see is that the type checker hates 
me and wants to force me to write everything the long way round...



More information about the Haskell-Cafe mailing list