Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell assignment type

Tags:

haskell

From the haskell.org website: every expression has a type. So what is the type of

main = putStrLn "Hello, World!"

I would like to know not what the type of main is, but what the type of the whole line is. Also, is it possible to get this type somehow in ghci? I tried

:t (main = putStrLn "Hello, World!")

but this does not work.

like image 592
Gregory Bleiker Avatar asked Jan 04 '21 13:01

Gregory Bleiker


1 Answers

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 ()
like image 132
chepner Avatar answered Sep 23 '22 11:09

chepner