Opened 15 years ago

Closed 10 years ago

Last modified 5 years ago

#414 closed merge (fixed)

GHC does not eforce that Main exports main

Reported by: simonpj Owned by: igloo
Priority: lowest Milestone: 6.12.2
Component: Compiler Version: 6.10.4
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: module/T414
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by simonmar)

The Haskell 98 report says "A Haskell program is a 
collection of
modules, one of which, by convention, must be called 
Main and must
export the value main." However, the program below 
builds and executes

module Main() -- should be "module Main" or "module 
main = putStrLn "Hello, World"

$ runghc Main.hs
Hello, World

Originally reported by Brian Smith 

Change History (15)

comment:1 Changed 14 years ago by simonmar

Description: modified (diff)
Version: None6.4.1

comment:2 Changed 13 years ago by igloo

Milestone: 6.8
Test Case: mod174

comment:3 Changed 12 years ago by simonmar

Architecture: Unknown
difficulty: Unknown
Operating System: Unknown
Owner: nobody deleted
Status: assignednew

comment:4 Changed 12 years ago by igloo

Milestone: 6.8 branch_|_

comment:5 Changed 11 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:6 Changed 11 years ago by simonmar

Operating System: UnknownUnknown/Multiple

comment:7 Changed 10 years ago by seanmcl

Type of failure: None/Unknown

Verified it's still a problem in 6.10.4.

comment:8 Changed 10 years ago by simonmar

Owner: set to simonmar

comment:9 Changed 10 years ago by simonmar

Milestone: _|_6.12.2
Owner: changed from simonmar to igloo
Type: bugmerge


Mon Nov 30 11:23:27 GMT 2009  Simon Marlow <>
  * Check whether the main function is actually exported (#414)

comment:10 Changed 10 years ago by igloo

Mon Nov 30 04:04:04 PST 2009  Simon Marlow <>
  * add a test for #414

comment:11 Changed 10 years ago by igloo

Resolution: Nonefixed
Status: newclosed

Both merged

comment:12 Changed 6 years ago by Ian Lynagh <igloo@…>

In 5a54c38e846dd4774b0a0cf285d12b353bfcb864/ghc:

Add test mod174 for trac #414 (GHC does not enforce that Main exports main)

comment:13 Changed 6 years ago by Ian Lynagh <igloo@…>

In 49ca979dc07fb0bfb9a790630cb2eb41750a96bd/ghc:

mod174/mod175 are broken: trac bugs #414 and #437

comment:14 Changed 5 years ago by thomie

Test Case: mod174module/T414

comment:15 Changed 5 years ago by Austin Seipp <austin@…>

In 0fa20726b0587530712677e50a56c2b03ba43095/ghc:

Error out on `Main` without `main` in GHCi (#7765)

GHC does 2 validation checks for module `Main`:
* does `main` exist
* is `main` exported (#414)

The second check is done in ghc as well as in ghci (and runghc and ghc -e).
The first check however is currently not done in ghci, to prevent "'main' is
not in scope" errors when loading simple scripts. See commit d28ba8c8009 for
more information.

This commit tightens the special case for ghci. When the file does not contain
a main function, but does contain an explicit module header (i.e. "module Main
where"), then /do/ raise an error in ghci (and runghc and ghc -e) as well

Test Plan:
module/T7765: a module Main with an explicit module header but without a
main function should be an error for all Ways.

Additionaly: delete test module/mod174. It was added in commit 5a54c38, but it
is a duplicate of module/T414.

Reviewers: austin

Reviewed By: austin

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #7765
Note: See TracTickets for help on using tickets.