Haskell assignment type

main = putStrLn "Hello, World!" is not an expression, and thus does not have a type. It's a definition, which assigns a value of type IO () (resulting from the evaluation of putStrLn :: String -> IO ()) to the name main.

Following the definition, you can find the type of main:

> :t main
main :: IO ()

every expression has a type.

That is correct, but a declaration is not an expression. 1+1 is an expression, a = 1+1 is not an expression, but a declaration.

I would like to know not what the type of main is, but what the type of the whole line is.

This has no type, you simply define a variable with the given expression. The expression putStrLn "Hello, World!" has type IO (), since putStrLn has type putStrLn :: String -> IO ().

Tags:

Haskell