Skip to content

Instantly share code, notes, and snippets.

@chessai
Created September 30, 2018 19:09
Show Gist options
  • Save chessai/3713ce376bce77ea3dd7448644de11f4 to your computer and use it in GitHub Desktop.
Save chessai/3713ce376bce77ea3dd7448644de11f4 to your computer and use it in GitHub Desktop.
diff --git a/compiler/typecheck/TcRnExports.hs b/compiler/typecheck/TcRnExports.hs
index dbe2b4b22b..1b57608a41 100644
--- a/compiler/typecheck/TcRnExports.hs
+++ b/compiler/typecheck/TcRnExports.hs
@@ -33,7 +33,7 @@ import DataCon
import PatSyn
import Maybes
import Util (capitalise)
-
+import FastString (fsLit)
import Control.Monad
import DynFlags
@@ -124,19 +124,18 @@ tcRnExports explicit_mod exports
-- list, to avoid bleating about re-exporting a deprecated
-- thing (especially via 'module Foo' export item)
do {
- -- If the module header is omitted altogether, then behave
- -- as if the user had written "module Main(main) where..."
- -- EXCEPT in interactive mode, when we behave as if he had
+ -- In interactive mode, we behave as if he had
-- written "module Main where ..."
- -- Reason: don't want to complain about 'main' not in scope
- -- in interactive mode
; dflags <- getDynFlags
+ ; let default_main = case mainFunIs dflags of
+ Just main_fun -> mkUnqual varName (fsLit main_fun)
+ Nothing -> main_RDR_Unqual
; let real_exports
| explicit_mod = exports
| ghcLink dflags == LinkInMemory = Nothing
| otherwise
= Just (noLoc [noLoc (IEVar noExt
- (noLoc (IEName $ noLoc main_RDR_Unqual)))])
+ (noLoc (IEName $ noLoc default_main)))])
-- ToDo: the 'noLoc' here is unhelpful if 'main'
-- turns out to be out of scope
diff --git a/docs/users_guide/bugs.rst b/docs/users_guide/bugs.rst
index aee8dc5842..0290622b62 100644
--- a/docs/users_guide/bugs.rst
+++ b/docs/users_guide/bugs.rst
@@ -173,6 +173,34 @@ same context. For example, this is fine: ::
.. _infelicities-Modules:
+Default Module headers with -main-is
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The Haskell2010 report specifies in <https://www.haskell.org/onlinereport/haskell2010/haskellch5.html#x11-990005.1> that
+
+ "An abbreviated form of module, consisting only of the module body,
+ is permitted. If this is used, the header is assumed to be
+ `module Main(main) where`."
+
+Consider the following program: ::
+
+ -- file: Main.hs
+ program :: IO ()
+ program = return ()
+
+Under the report, this would fail with ``ghc -main-is Main.program Main.hs``
+with the following errors: ::
+
+ Main.hs:1:1: error:
+ Not in scope: 'main'
+ Perhaps you meant 'min' (imported from Prelude)
+
+ Main.hs:1:1: error:
+ The main IO action 'program' is not exported by module 'Main'
+
+GHC's flag '-main-is' allows one to change the entry point name so that
+the above example would succeed.
+
Module system and interface files
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment