diff options
author | Chris Smith <cdsmith@gmail.com> | 2018-11-17 12:40:23 +0100 |
---|---|---|
committer | Krzysztof Gogolewski <krz.gogolewski@gmail.com> | 2018-11-17 13:52:26 +0100 |
commit | 0e7790abf7d19d19f84c86dc95e50beb65462d12 (patch) | |
tree | 4868453d4f01abd14543317e7a0e3a93d73f2d19 /docs/users_guide/bugs.rst | |
parent | 798c943781e14b7111431d3c7193c93fcc5ffa3e (diff) | |
download | haskell-0e7790abf7d19d19f84c86dc95e50beb65462d12.tar.gz |
Fix trac #15702, as a followon to fix for #13704.
Summary:
The effect of this change is that -main-is changes the default
export list for the main module, but does not apply the same
change to non-main modules. This fixes some cases where -main-is
was used to wrap a module that expected that default behavior
(exporting `main`, even when that wasn't the main entry point
name).
Reviewers: mpickering, monoidal, bgamari
Subscribers: rwbarton, carter
GHC Trac Issues: #13704, #15702
Differential Revision: https://phabricator.haskell.org/D5322
Diffstat (limited to 'docs/users_guide/bugs.rst')
-rw-r--r-- | docs/users_guide/bugs.rst | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/docs/users_guide/bugs.rst b/docs/users_guide/bugs.rst index 0290622b62..96cdd25f5a 100644 --- a/docs/users_guide/bugs.rst +++ b/docs/users_guide/bugs.rst @@ -171,35 +171,51 @@ same context. For example, this is fine: :: g :: Ord a => a -> Bool g y = (y <= y) || f True -.. _infelicities-Modules: +.. _infelicities-default-exports: Default Module headers with -main-is ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -The Haskell2010 report specifies in <https://www.haskell.org/onlinereport/haskell2010/haskellch5.html#x11-990005.1> that +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`." +GHC's ``-main-is`` option can be used to change the name of the top-level entry +point from ``main`` to any other variable. When compiling the main module and +``-main-is`` has been used to rename the default entry point, GHC will also use +the alternate name in the default export list. + 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: :: +GHC will successfully compile this module with +``ghc -main-is Main.program Main.hs``, because the default export list +will include ``program`` rather than ``main``, as the Haskell Report +typically requires. + +This change only applies to the main module. Other modules will still export +``main`` from a default export list, regardless of the ``-main-is`` flag. +This allows use of ``-main-is`` with existing modules that export ``main`` via +a default export list, even when ``-main-is`` points to a different entry +point, as in this example (compiled with ``-main-is MainWrapper.program``). :: - Main.hs:1:1: error: - Not in scope: 'main' - Perhaps you meant 'min' (imported from Prelude) + -- file MainWrapper.hs + module MainWrapper where + import Main - Main.hs:1:1: error: - The main IO action 'program' is not exported by module 'Main' + program :: IO () + program = putStrLn "Redirecting..." >> main + + -- file Main.hs + main :: IO () + main = putStrLn "I am main." -GHC's flag '-main-is' allows one to change the entry point name so that -the above example would succeed. +.. _infelicities-Modules: Module system and interface files ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |