[Haskell-cafe] Re: Very crazy

Aaron Denney wnoise at ofb.net
Tue Sep 25 06:48:53 EDT 2007

On 2007-09-25, Andrew Coppin <andrewcoppin at btinternet.com> wrote:
> I just found it rather surprising. Every time *I* try to compose with 
> functions of more than 1 argument, the type checker complains. 
> Specifically, suppose you have
>   foo = f3 . f2 . f1
> Assuming those are all 1-argument functions, it works great. But if f1 
> is a *two* argument function (like map is), the type checker refuses to 
> allow it, and I have to rewrite it as
>   foo x y = f3 $ f2 $ f1 x y
> which is really extremely annoying...
> I'm just curiose as to why the type checker won't let *me* do it, but it 
> will let *you* do it. (Maybe it hates me?)

Don't anthropomorphize computers.  They hate it when you do that.

I'm guessing the problem is probably incorrect parenthesizing.

foo x y = f3 . f2 . f1 x y

won't typecheck, but 

foo x y = (f3 . f2 . f1) x y


Function application is the highest precedence, so 
the first definition is parsed as 

foo x y = f3 . f2 . (f1 x y)

which will only type-check if f1 has 3 or more arguments, as (f1 x y)
must be a function.

The trickier parts are more than 1 argument functions as the first
argument to (.).  Are you sure your failed attempts weren't of this

Aaron Denney

More information about the Haskell-Cafe mailing list