Default module header `module Main where`

Hi, a very small proposal to be considered for Haskell': Currently, the report states 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’. I propose to change that to 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 where’. The rationale is that a main-less main module is still useful, e.g. when you are working a lot in GHCi, and offload a few extensions to a separate file. Currently, tools like hdevtools will complain about a missing main function when editing such a file. It would also work better with GHC’s -main-is flag, and avoid problems like the one described in https://ghc.haskell.org/trac/ghc/ticket/13704 I don’t see any downsides. When compiling to a binary, implementations are still able to detect that a Main module is not imported by any other module and only the main function is used, and optimize as if only main were exported. Greetings, Joachim -- Joachim “nomeata” Breitner mail@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org

That seems fairly reasonable to me.
-Iavor
On Tue, May 16, 2017 at 7:18 AM, Joachim Breitner
Hi,
a very small proposal to be considered for Haskell':
Currently, the report states
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’.
I propose to change that to
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 where’.
The rationale is that a main-less main module is still useful, e.g. when you are working a lot in GHCi, and offload a few extensions to a separate file. Currently, tools like hdevtools will complain about a missing main function when editing such a file.
It would also work better with GHC’s -main-is flag, and avoid problems like the one described in https://ghc.haskell.org/trac/ghc/ticket/13704
I don’t see any downsides. When compiling to a binary, implementations are still able to detect that a Main module is not imported by any other module and only the main function is used, and optimize as if only main were exported.
Greetings, Joachim
-- Joachim “nomeata” Breitner mail@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org _______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime

Agreed, this sounds sensible. Can anyone think of any unintended consequences? -Jose On Tue, May 16, 2017, at 09:50 AM, Iavor Diatchki wrote:
That seems fairly reasonable to me.
-Iavor
On Tue, May 16, 2017 at 7:18 AM, Joachim Breitner
wrote:>> Hi, a very small proposal to be considered for Haskell':
Currently, the report states
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’.
I propose to change that to
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 where’.
The rationale is that a main-less main module is still useful, e.g.>> when you are working a lot in GHCi, and offload a few extensions to a>> separate file. Currently, tools like hdevtools will complain about a>> missing main function when editing such a file.
It would also work better with GHC’s -main-is flag, and avoid problems>> like the one described in https://ghc.haskell.org/trac/ghc/ticket/13704>>
I don’t see any downsides. When compiling to a binary, implementations>> are still able to detect that a Main module is not imported by any other module and only the main function is used, and optimize as if>> only main were exported.
Greetings, Joachim
-- Joachim “nomeata” Breitner mail@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org>> _______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
_________________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime

GHCIs current behavior seems inconsistent with this, why is foo accessible
and why don't I get an unused warning like i do if i have an explicit
`module Main (main) where`?
```
$ cat Main.hs
main :: IO ()
main = pure ()
foo :: Int
foo = 1
$ ghci Main.hs -Wall
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /Users/adam.bergmark/.ghci
[1 of 1] Compiling Main ( Main.hs, interpreted )
Ok, modules loaded: Main.
λ foo
1
```
On Tue, 16 May 2017 at 19:00 José Manuel Calderón Trilla
Agreed, this sounds sensible.
Can anyone think of any unintended consequences?
-Jose
On Tue, May 16, 2017, at 09:50 AM, Iavor Diatchki wrote:
That seems fairly reasonable to me.
-Iavor
On Tue, May 16, 2017 at 7:18 AM, Joachim Breitner < mail@joachim-breitner.de> wrote:
Hi,
a very small proposal to be considered for Haskell':
Currently, the report states
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’.
I propose to change that to
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 where’.
The rationale is that a main-less main module is still useful, e.g. when you are working a lot in GHCi, and offload a few extensions to a separate file. Currently, tools like hdevtools will complain about a missing main function when editing such a file.
It would also work better with GHC’s -main-is flag, and avoid problems like the one described in https://ghc.haskell.org/trac/ghc/ticket/13704
I don’t see any downsides. When compiling to a binary, implementations are still able to detect that a Main module is not imported by any other module and only the main function is used, and optimize as if only main were exported.
Greetings, Joachim
-- Joachim “nomeata” Breitner mail@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org _______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
*_______________________________________________* Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
_______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime

you're inside the module, so you have access to all top-level bindings, not just to the export list. the issue with the implicit `module Main(main) where` is that it errors if main is not defined, even though that's a perfectly harmless situation. (i hope i got the question right?) On Tue, May 16, 2017 at 05:53:17PM +0000, Adam Bergmark wrote:
Date: Tue, 16 May 2017 17:53:17 +0000 From: Adam Bergmark
To: José Manuel Calderón Trilla , haskell-prime@haskell.org Subject: Re: Default module header `module Main where` GHCIs current behavior seems inconsistent with this, why is foo accessible and why don't I get an unused warning like i do if i have an explicit `module Main (main) where`?
``` $ cat Main.hs main :: IO () main = pure ()
foo :: Int foo = 1
$ ghci Main.hs -Wall GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /Users/adam.bergmark/.ghci [1 of 1] Compiling Main ( Main.hs, interpreted ) Ok, modules loaded: Main.
λ foo 1 ```
On Tue, 16 May 2017 at 19:00 José Manuel Calderón Trilla
wrote: Agreed, this sounds sensible.
Can anyone think of any unintended consequences?
-Jose
On Tue, May 16, 2017, at 09:50 AM, Iavor Diatchki wrote:
That seems fairly reasonable to me.
-Iavor
On Tue, May 16, 2017 at 7:18 AM, Joachim Breitner < mail@joachim-breitner.de> wrote:
Hi,
a very small proposal to be considered for Haskell':
Currently, the report states
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’.
I propose to change that to
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 where’.
The rationale is that a main-less main module is still useful, e.g. when you are working a lot in GHCi, and offload a few extensions to a separate file. Currently, tools like hdevtools will complain about a missing main function when editing such a file.
It would also work better with GHC’s -main-is flag, and avoid problems like the one described in https://ghc.haskell.org/trac/ghc/ticket/13704
I don’t see any downsides. When compiling to a binary, implementations are still able to detect that a Main module is not imported by any other module and only the main function is used, and optimize as if only main were exported.
Greetings, Joachim
-- Joachim “nomeata” Breitner mail@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org _______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
*_______________________________________________* Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
_______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
_______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
-- https://zerobuzz.net/ mf@zerobuzz.net +49 179 7733 223

One potential difference between the two is that the current behavior
allows the `Main` module to import `main` from another module, while the
new behavior would fail in that case.
For example, a file that has only a single line:
import SomeOtherModule(main)
This still seems like a fairly unusual corner case (with an obvious work
around), so I don't think it matters much, but I thought I'd mention it so
that we are aware of it.
On Tue, May 16, 2017 at 7:18 AM, Joachim Breitner
Hi,
a very small proposal to be considered for Haskell':
Currently, the report states
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’.
I propose to change that to
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 where’.
The rationale is that a main-less main module is still useful, e.g. when you are working a lot in GHCi, and offload a few extensions to a separate file. Currently, tools like hdevtools will complain about a missing main function when editing such a file.
It would also work better with GHC’s -main-is flag, and avoid problems like the one described in https://ghc.haskell.org/trac/ghc/ticket/13704
I don’t see any downsides. When compiling to a binary, implementations are still able to detect that a Main module is not imported by any other module and only the main function is used, and optimize as if only main were exported.
Greetings, Joachim
-- Joachim “nomeata” Breitner mail@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org _______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime

On 2017-05-16 10:18 AM, Joachim Breitner wrote:
Hi,
a very small proposal to be considered for Haskell':
I like it, but it should probably be a GHC proposal first. I don't think Haskell' is supposed to make any change to the standard that hasn't been already implemented and tested. In this particular case, GHC HQ might opt to implement your proposal but hide it behind a command-line option, or to enable it by default only in GHCi. There are already precedents for this.
Currently, the report states
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’.
I propose to change that to
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 where’.
The rationale is that a main-less main module is still useful, e.g. when you are working a lot in GHCi, and offload a few extensions to a separate file. Currently, tools like hdevtools will complain about a missing main function when editing such a file.
It would also work better with GHC’s -main-is flag, and avoid problems like the one described in https://ghc.haskell.org/trac/ghc/ticket/13704
I don’t see any downsides. When compiling to a binary, implementations are still able to detect that a Main module is not imported by any other module and only the main function is used, and optimize as if only main were exported.
Greetings, Joachim
_______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
-- Mario Blazevic mblazevic@stilo.com Stilo International This message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure, copying, or distribution is strictly prohibited. If you are not the intended recipient(s) please contact the sender by reply email and destroy all copies of the original message and any attachments.

as a guideline what you say is true, and at least in this case as the
motivation is user focused it should be validated thusly :)
On Fri, May 19, 2017 at 5:35 PM, Mario Blažević
On 2017-05-16 10:18 AM, Joachim Breitner wrote:
Hi,
a very small proposal to be considered for Haskell':
I like it, but it should probably be a GHC proposal first. I don't think Haskell' is supposed to make any change to the standard that hasn't been already implemented and tested. In this particular case, GHC HQ might opt to implement your proposal but hide it behind a command-line option, or to enable it by default only in GHCi. There are already precedents for this.
Currently, the report states
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’.
I propose to change that to
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 where’.
The rationale is that a main-less main module is still useful, e.g. when you are working a lot in GHCi, and offload a few extensions to a separate file. Currently, tools like hdevtools will complain about a missing main function when editing such a file.
It would also work better with GHC’s -main-is flag, and avoid problems like the one described in https://ghc.haskell.org/trac/ghc/ticket/13704
I don’t see any downsides. When compiling to a binary, implementations are still able to detect that a Main module is not imported by any other module and only the main function is used, and optimize as if only main were exported.
Greetings, Joachim
_______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
-- Mario Blazevic mblazevic@stilo.com Stilo International
This message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure, copying, or distribution is strictly prohibited. If you are not the intended recipient(s) please contact the sender by reply email and destroy all copies of the original message and any attachments.
_______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime

Hi, I thought about this. But I fear that this will require a language extension or flag, and then the developers (quite rightly) say that it does not pull its weight of supporting both variants, and it gets lost. But maybe I should give it a shot if they accept it. Joachim Am Freitag, den 19.05.2017, 17:35 -0400 schrieb Mario Blažević:
On 2017-05-16 10:18 AM, Joachim Breitner wrote:
Hi,
a very small proposal to be considered for Haskell':
I like it, but it should probably be a GHC proposal first. I don't think Haskell' is supposed to make any change to the standard that hasn't been already implemented and tested. In this particular case, GHC HQ might opt to implement your proposal but hide it behind a command-line option, or to enable it by default only in GHCi. There are already precedents for this.
Currently, the report states
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’.
I propose to change that to
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 where’.
The rationale is that a main-less main module is still useful, e.g. when you are working a lot in GHCi, and offload a few extensions to a separate file. Currently, tools like hdevtools will complain about a missing main function when editing such a file.
It would also work better with GHC’s -main-is flag, and avoid problems like the one described in https://ghc.haskell.org/trac/ghc/ticket/1 3704
I don’t see any downsides. When compiling to a binary, implementations are still able to detect that a Main module is not imported by any other module and only the main function is used, and optimize as if only main were exported.
Greetings, Joachim
_______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-prime
-- Joachim Breitner mail@joachim-breitner.de http://www.joachim-breitner.de/

On Fri, May 19, 2017 at 06:32:30PM -0400, Joachim Breitner wrote:
I thought about this. But I fear that this will require a language extension or flag, and then the developers (quite rightly) say that it does not pull its weight of supporting both variants, and it gets lost. But maybe I should give it a shot if they accept it.
Indeed this strikes me as a not a good extension to have: every extension further fragments the ecosystem and is yet another thing to care about if you are reading someone else's code, etc. - the cost probably outweights the benefit on this one. But it seems a good proposal for H2020, as (if it is accepted), the costs linked with an extension/flag (added complexity, fragmentation of the community) aren't there. The "extensions before report modification" is a solid rule, maybe the committee wants to add an exception for proposals which cannot realistically be "packaged" (and achieve widespread use) into extensions?

On 19/05/17 07:12 PM, Francesco Ariis wrote:
I thought about this. But I fear that this will require a language extension or flag, and then the developers (quite rightly) say that it does not pull its weight of supporting both variants, and it gets lost. But maybe I should give it a shot if they accept it. Indeed this strikes me as a not a good extension to have: every extension further fragments the ecosystem and is yet another thing to care about if you are reading someone else's code, etc. - the cost probably outweights
On Fri, May 19, 2017 at 06:32:30PM -0400, Joachim Breitner wrote: the benefit on this one.
But it seems a good proposal for H2020, as (if it is accepted), the costs linked with an extension/flag (added complexity, fragmentation of the community) aren't there.
The "extensions before report modification" is a solid rule, maybe the committee wants to add an exception for proposals which cannot realistically be "packaged" (and achieve widespread use) into extensions?
I feel it's rather ironic that there exists a class of proposals that are considered acceptable for Haskell' but too radical for GHC, considering that the stands are usually completely opposite. The obvious way out of this conundrum is to communicate with GHC. If the Haskell' committee gives a proposal some sort of conditional acceptance status, that should count for something with the GHC HQ. After all, they'd presumably have to implement it once it's officially a part of the next standard, so implementing it sooner as a proposal is not that much more to ask.

Hi for good measure, I drafted a GHC proposal: https://github.com/ghc-proposals/ghc-proposals/pull/53 Greetins, Joachim -- Joachim “nomeata” Breitner mail@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org

On Tue, May 16, 2017 at 10:18:51AM -0400, Joachim Breitner wrote:
Currently, the report states
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’.
I propose to change that to
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 where’.
I don’t see any downsides. When compiling to a binary, implementations are still able to detect that a Main module is not imported by any other module and only the main function is used, and optimize as if only main were exported.
Initially I was concerned that this proposal would implicitly export everything from Main, which would then prevent compilers from warning about unused values, since they can't tell if seemingly-unused things are in fact being exported for use elsewhere (perhaps by a program that is not currently being compiled, so looking at what exported values are used elsewhere is not a solution). Then I started wondering if a standards-compliant Haskell program can ever import anything from a module called Main (because module names should be unique across a program, and there should be a Main module at the root of the dependency graph). Then I started wondering about a Main module that was mutually recursive with another module. I've ended up uncertain, so I'll just throw it out there: are unused value warnings affected by this proposal?

Hi, Am Mittwoch, den 24.05.2017, 21:50 +0800 schrieb Ben Millwood:
Initially I was concerned that this proposal would implicitly export everything from Main, which would then prevent compilers from warning about unused values, since they can't tell if seemingly-unused things are in fact being exported for use elsewhere (perhaps by a program that is not currently being compiled, so looking at what exported values are used elsewhere is not a solution).
Then I started wondering if a standards-compliant Haskell program can ever import anything from a module called Main (because module names should be unique across a program, and there should be a Main module at the root of the dependency graph).
Then I started wondering about a Main module that was mutually recursive with another module.
I've ended up uncertain, so I'll just throw it out there: are unused value warnings affected by this proposal?
that is a very good point, thanks for raising it. I have two different answers: A) You are right. Everything is exported, so without an explicit module header, unused value warnings would not happen. This is undesirable, and thus this proposal should probably be killed. B) Warnings are not specified by the report, and the implementation is free to warn about unused bindings in a headerless Main module, based on the implementation’s knowledge that even though these are exported, they are not used. But answer B is less convincing in the corner case of Main being mutually recursive with another module. (Who would do that without naming Main? But yes, it is a problem.) So your point makes me less convinced about my proposal. So maybe the solution is to not make this change, but rather change fix the original problem (tools like IDEs complaining about the lack of “main” in a headerless, main-less module) by being a bit more liberal in these tools. I still believe that the -main-is flag should affect the default module header (GHC #13704), but that is a separate issue. Well, thanks for the constructive feedback everyone :-) Joachim -- Joachim Breitner mail@joachim-breitner.de http://www.joachim-breitner.de/

On 2017-05-24 10:28 AM, Joachim Breitner wrote:
I've ended up uncertain, so I'll just throw it out there: are unused value warnings affected by this proposal?
that is a very good point, thanks for raising it. I have two different answers:
A) You are right. Everything is exported, so without an explicit module header, unused value warnings would not happen. This is undesirable, and thus this proposal should probably be killed.
B) Warnings are not specified by the report, and the implementation is free to warn about unused bindings in a headerless Main module, based on the implementation’s knowledge that even though these are exported, they are not used.
I would say B') Warnings are not specified by the report. We can pretty much stop there. If you want to go deeper, IMO the compiler should just suppress the warnings by default. A headerless module would normally be used only for examples and quick tests, unused binding warnings would be a nuisance for that use case.
But answer B is less convincing in the corner case of Main being mutually recursive with another module. (Who would do that without naming Main? But yes, it is a problem.)
When dicussing a software-engineering issue like compiler warnings, as opposed to a language-design issue, it doesn't make sense to concentrate on corner cases. A non-root Main module is already a corner case. A non-root header-less Main module is a corner inside a corner case. Whoever does that may miss some compiler warnings, depending on the compiler implementation. I won't lose any sleep over that. If the compiler developers do, they have the option to issue the unused-binding warnings only when a header-less module is imported.
participants (10)
-
Adam Bergmark
-
Ben Millwood
-
Carter Schonwald
-
Francesco Ariis
-
Iavor Diatchki
-
Joachim Breitner
-
José Manuel Calderón Trilla
-
Mario Blažević
-
Mario Blažević
-
Matthias Fischmann