[Haskell-cafe] function composition

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


I have a basic question concerning function composition. I have used 
to write a composition function:

Prelude> let f°g = f g
Prelude> let p = (*2)
Prelude> let q = (+3)
Prelude> p°q 4
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

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

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

Thanks in advance,


More information about the Haskell-Cafe mailing list