diff --git a/message-index/messages/GHC-67120/example1/after/Lib.hs b/message-index/messages/GHC-67120/example1/after/Lib.hs new file mode 100644 index 00000000..4cf406c5 --- /dev/null +++ b/message-index/messages/GHC-67120/example1/after/Lib.hs @@ -0,0 +1,4 @@ +module Lib where + +factorial :: Int -> Int +factorial n = product [1..n] diff --git a/message-index/messages/GHC-67120/example1/before/Lib.hs b/message-index/messages/GHC-67120/example1/before/Lib.hs new file mode 100644 index 00000000..9ae85065 --- /dev/null +++ b/message-index/messages/GHC-67120/example1/before/Lib.hs @@ -0,0 +1,2 @@ +factorial :: Int -> Int +factorial n = product [1..n] diff --git a/message-index/messages/GHC-67120/example1/index.md b/message-index/messages/GHC-67120/example1/index.md new file mode 100644 index 00000000..cde5ee14 --- /dev/null +++ b/message-index/messages/GHC-67120/example1/index.md @@ -0,0 +1,9 @@ +--- +title: Missing module header +--- + +In this example, the file `Lib.hs` is intended to contain a module called `Lib` +which is not supposed to be the main module. However, the file is missing a +module header, so GHC defaults to the module name `Main` and expects the `main` +function. Adding an explicit module header with the name `Lib` solves this +issue. diff --git a/message-index/messages/GHC-67120/example2/after/Main.hs b/message-index/messages/GHC-67120/example2/after/Main.hs new file mode 100644 index 00000000..ecf15d6d --- /dev/null +++ b/message-index/messages/GHC-67120/example2/after/Main.hs @@ -0,0 +1,2 @@ +main :: IO () +main = putStrLn "Hello, World!" diff --git a/message-index/messages/GHC-67120/example2/before/Main.hs b/message-index/messages/GHC-67120/example2/before/Main.hs new file mode 100644 index 00000000..2380be4f --- /dev/null +++ b/message-index/messages/GHC-67120/example2/before/Main.hs @@ -0,0 +1,2 @@ +notMain :: IO () +notMain = putStrLn "Hello, World!" diff --git a/message-index/messages/GHC-67120/example2/index.md b/message-index/messages/GHC-67120/example2/index.md new file mode 100644 index 00000000..b5cfe809 --- /dev/null +++ b/message-index/messages/GHC-67120/example2/index.md @@ -0,0 +1,7 @@ +--- +title: main has wrong name +--- + +In this example, the `notMain` value is the intended entry point of the program, +but it is not called `main` so GHC does not find it. Renaming `notMain` to +`main` solves the issue. diff --git a/message-index/messages/GHC-67120/index.md b/message-index/messages/GHC-67120/index.md new file mode 100644 index 00000000..e1295afd --- /dev/null +++ b/message-index/messages/GHC-67120/index.md @@ -0,0 +1,49 @@ +--- +title: Missing main +summary: The IO action ‘main’ is not defined in module ‘Main’. +introduced: 9.8.1 +severity: error +--- + +GHC expects the `Main` module to define a function called `main` which it can +use as the entry point of your program. + +This error can also occur in unnamed modules, because GHC will default to the +module name `Main` for such modules. + +If you just want GHC to produce an object file without an entry point, then you +can give your module a name other than `Main` by putting a module header at the +top of your file (below language pragmas and compiler options), for example as +follows: + +``` +module Foo where +``` + +The conventions around `main` are defined in the second paragraph of Chapter 5 +of [The Haskell 2010 Report](https://www.haskell.org/onlinereport/haskell2010/haskellch5.html#x11-980005), + +> A Haskell program is a collection of modules, one of which, by convention, +> must be called `Main` and must export the value `main`. The value of the +> program is the value of the identifier `main` in module `Main`, which must be +> a computation of type `IO t` for some type `t` (see Chapter 7). When the +> program is executed, the computation `main` is performed, and its result (of +> type `t`) is discarded. + +## Example error text + +``` +example1/before/Lib.hs:1:1: error: [GHC-67120] + The IO action ‘main’ is not defined in module ‘Main’ + | +1 | factorial :: Int -> Int + | ^ +``` + +``` +example2/before/Main.hs:1:1: error: [GHC-67120] + The IO action ‘main’ is not defined in module ‘Main’ + | +1 | notMain :: IO () + | ^ +```