Haskell: Brackets work but $ throws an error

haskell

Solution

`$` is not a syntax sugar that puts `(` in current place and `)` in the end of the line.

So `print $ read "15" :: Integer` is interpreted like `(print (read "15")) :: Integer`. It happens because `$ :: (a -> b) -> a -> b` (functional composition infix operator) takes two functions `print` and `read "15"` and «apply» them one by another. `:: Integer` seems to be not a function here, it is more like a keyword, so `$` doesn't work the way you expected.

Problem

I expect the following code to convert "15" into a integer and print the result, but it throws an error. ``` main = print $ read "15" :: Integer Couldn't match expected type `Integer' with actual type `IO ()' ``` But just using `main = print (read "15" :: Integer)` runs fine. I was under the impression that $ effectively surrounds the rest of the line in brackets. Why doesn't $ work in this case?

Original source