In java we always write:
public static void main(String[] args){...}
when we want to start writing a program.
My question i
Short answer: No, we have to declare a main =
, but not a do
.
The main
must be an IO monad type (so IO a
) where a
is arbitrary (since it is ignored), as is written here:
The use of the name
main
is important:main
is defined to be the entry point of a Haskell program (similar to themain
function in C), and must have anIO
type, usuallyIO ()
.
But you do not necessary need do
notation. Actually do is syntactical sugar. Your main
is in fact:
main =
putStrLn "What's your name?" >> getLine >>= \n -> putStrLn ("Hello " ++ n)
Or more elegantly:
main = putStrLn "What's your name?" >> getLine >>= putStrLn . ("Hello " ++)
So here we have written a main
without do
notation. For more about desugaring do
notation, see here.