I was reading this answer and asked some people why "main" is used two times with different punctuation in front.

main :: IO ()
main =  do c <- getChar
         putChar c

The answer was that the first line declares the type and the second line declares the function. My doubt is, why do we have to say the type before the definition? Wouldn't the type be implied by the definition and syntax?

  • 1
    $\begingroup$ You don't. It is. Some people declare it anyway so they can remember what it is. (you might think it's silly for main, but a big program has a lot of function with a lot of different types) $\endgroup$
    – user253751
    Nov 17, 2022 at 13:34


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.