I have a problem with typing anonymous functions in Haskell. For example when we have:
\x -> x 5
The type checked in GHCI is Num t1 => (t1 -> t2) -> t2
while I was sure it is the opposite.Similarly type
\x -> a * x
is Num a => a -> a
(I know we need to assume that a is an Integer as the type of (*) is Int -> Int -> Int (without typeclasses).
Another example would be
\f -> f x
And as far as I checked is sth like (a -> b) -> b
But I am totally concerned about typing anonymous function. What is the magic power to understand this? Maybe a way to rewrite this function to a "normal" one to see the type clearly?
SO MY QUESTION IS: How do we get these types? Where they come from and how to evaluate this?