'Where is Haskell's or GHC's main defined?
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?
Solution 1:[1]
A Haskell program is a collection of modules, one of which, by convention, must be called
Mainand must export the valuemain. The value of the program is the value of the identifiermainin moduleMain, which must be a computation of typeIO ?for some type?(see Chapter 7). When the program is executed, the computationmainis performed, and its result (of type?) is discarded.
https://www.haskell.org/onlinereport/haskell2010/haskellch5.html#dx11-98001
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
