[Haskell-cafe] function type def

jerzy.karczmarczuk at info.unicaen.fr jerzy.karczmarczuk at info.unicaen.fr
Tue Apr 1 15:35:16 EDT 2008

PR Stanley: 

> I know sort of instinctively why it is so but 
> can't think of the formal rationale for it:
> f g x = g (g x) :: (t -> t) -> (t -> t)

First of all - it is not the definition f g x = ... :: (t-> ...
but the type of the function which might be specified:
f :: (t->t)->t->t 

Then, the answer to:
> Why not
> (t -> t) -> t -> (t -> t)
> to take account of the argument x for g?

is simple. If t is the type of x, then g must be g :: t->t, you're right.
So f :: (t->t) -> t -> [the type of the result]
But this result is of the type t, it is g(g x), not (t->t), it is as
simple as that. Perhaps you didn't recognize that "->" is syntactically
a right-associative op, so
a->b->c   is equivalent to a->(b->c), or
(t->t)->t->t         equiv. to  (t->t)->(t->t) 

Jerzy Karczmarczuk 

More information about the Haskell-Cafe mailing list