In Haskell, the execution of a compiled program starts with executing main
in module Main
. This function must be of type IO ()
.
Which standard or reference defines the above?
Compare C (references C11 standard (ISO/IEC 9899:2011) 5.1.2.2.1 Program startup (p: 13)):
Every C program [...] contains the definition [...] of a function called main, which is the designated start of the program.
Haskell 2010 and Haskell 98 don't define main
formally (although there are several examples of functions called main
), instead saying:
We leave as implementation dependent the ways in which Haskell programs are to be manipulated, interpreted, compiled, etc.
GHC User's Guide instructs the user to create a main
function but never mentions its required type or that it is the start of the program execution. There are references to the Main
module but not main
function.
Compare C (references C11 standard (ISO/IEC 9899:2011) 5.1.2.2.1 Program startup (p: 13)):
Every C program [...] contains the definition [...] of a function called main, which is the designated start of the program.
Which standard or reference says that main
is the start of execution of a Haskell program?
CodePudding user response:
A Haskell program is a collection of modules, one of which, by convention, must be called
Main
and must export the valuemain
. The value of the program is the value of the identifiermain
in moduleMain
, which must be a computation of typeIO τ
for some typeτ
(see Chapter 7). When the program is executed, the computationmain
is performed, and its result (of typeτ
) is discarded.
https://www.haskell.org/onlinereport/haskell2010/haskellch5.html#dx11-98001