[Haskell-cafe] function composition

TP paratribulations at free.fr
Sun Jan 15 16:17:24 CET 2012


Hi,

I have a basic question concerning function composition. I have used 
http://www.haskell.org/tutorial/functions.html
to write a composition function:

Prelude> let f°g = f g
Prelude> let p = (*2)
Prelude> let q = (+3)
Prelude> p°q 4
14
Prelude> :t (°)
(°) :: (t1 -> t) -> t1 -> t

If I understand well, this means that the infix operator "°" takes a function 
of type t1, i.e. g in f°g, and applies f on it, which takes a type t1 as input 
and returns f(g) which is of type t. The final result is of type t. So the first 
argument is represented above by "(t1->t)", and the second by "t1", the final 
result being of type t.

However, I am not able to get the type of p°q

Prelude> :t p°q

<interactive>:1:3:
    Couldn't match expected type `Integer'
                with actual type `Integer -> Integer'
    In the second argument of `(°)', namely `q'
    In the expression: p ° q
Prelude> 

What's the problem here? How can I obtain the type of p°q?

Thanks in advance,

TP



More information about the Haskell-Cafe mailing list