Haskell function composition, type of (.)(.) and how it's presented
function-composition, haskell, operator-keyword, types
Solution
First off, you're being sloppy with your notation.
(.) = (f.g) x = f (g x) -- this isn't true
What is true:
(.) f g x = (f.g) x = f (g x)
(.) = \f g x -> f (g x)
And its type is given by
(.) :: (b -> c) -> (a -> b) -> a -> c
-- n.b. lower case, because they're type *variables*
Meanwhile
(.)(.) :: (a -> b -> d) -> a -> (c -> b) -> c -> d
-- I renamed the variables ghci gave me
Now let's work out
(.)(.) = (\f' g' x' -> f' (g' x')) (\f g x -> f (g x))
= \g' x' -> (\f g x -> f (g x)) (g' x')
= \g' x' -> \g x -> (g' x') (g x)
= \f y -> \g x -> (f y) (g x)
= \f y g x -> f y (g x)
= \f y g x -> (f y . g) x
= \f y g -> f y . g
And `($)`?
($) :: (a -> b) -> a -> b
f $ x = f x
`($)` is just function application. But whereas function application via juxtaposition is high precedence, function application via `($)` is low precedence.
square $ 1 + 2 * 3 = square (1 + 2 * 3)
square 1 + 2 * 3 = (square 1) + 2 * 3 -- these lines are different
Problem
So i know that: ``` (.) = (f.g) x = f (g x) ``` And it's type is (B->C)->(A->B)->A->C But what about: ``` (.)(.) = _? = _? ``` How this is represented? I thought of: ``` (.)(.) = (f.g)(f.g)x = f(g(f(g x))) // this (.)(.) = (f.g.h)x = f(g(h x)) // or this ``` But as far as i tried to get type of it, it's not correct to what GHCi tells me. So what are both "_?" Also - what does function/operator $ do?