[Haskell-cafe] Re: Very crazy

jerzy.karczmarczuk at info.unicaen.fr jerzy.karczmarczuk at info.unicaen.fr
Tue Sep 25 07:15:54 EDT 2007


Andrew Coppin writes: 

> ...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...

I suspect that it is you who hates the Haskell type-checker, forcing it
to work on expressions which go against the rules: precedence, and
normal order.
The transformation to combinators is doable, but one has to be careful.
Let's see: 

res p q = sum (zipWith (*) p q) = (sum . (zipWith (*) p)) q
res p = (sum .) (zipWith (*) p) = ((sum .) . (zipWith (*)) p 

res = (sum .) . (zipWith (*)) 

Certainly it is a kind of madness, since is hardly readable, but it
is correct. 

Jerzy Karczmarczuk 




More information about the Haskell-Cafe mailing list