hpack icon indicating copy to clipboard operation
hpack copied to clipboard

Default `main` to `Main` in `executables`

Open andreasabel opened this issue 4 years ago • 8 comments

Currently, if the user does not specify a main: in an executable section, they get an invalid .cabal file, since main-is is missing then.

Suggestion: default main: to Main.

Presumably, this should be done at the very end of the inference process to not interfere with #188, for instance. Only if just before writing the .cabal file we don't have a main, supply main-is: Main.

andreasabel avatar Feb 18 '21 18:02 andreasabel

@sol: Is this a feature you would want / accept?

andreasabel avatar Apr 04 '22 16:04 andreasabel

For me there are a couple of open questions that I currently don't have the time to look into (none exhaustive):

  1. There can be multiple executable sections. How would you handle this.
  2. What exactly is the difference between Main and Main.hs. We already overload the meaning of main.
  3. How to handle conditionals?
  4. Would you want to look at the file system at all?
  5. What is the weight benefit ratio from a users perspective?

sol avatar Apr 04 '22 18:04 sol

For me there are a couple of open questions that I currently don't have the time to look into (none exhaustive):

1. There can be multiple executable sections. How would you handle this.

Each executable section that does not supply main: gets main: Main. Of course you cannot drop main: if you have several executables in the same subdirectory. But I think this is self-evident.

2. What exactly is the difference between `Main` and `Main.hs`. We already overload the meaning of `main`.

cabal understands Main, which it seems to expand to Main.hs or Main.lhs. But hpack would not have to worry.

3. How to handle conditionals?

Not sure. I would have to understand conditionals first. There isn't much documentation on them, at least TheFourShowcases do not use them a lot. In a minimal implementation, one could abstain from the features if conditionals appear in executables or vice versa, this would probably still serve the other 99%.

4. Would you want to look at the file system at all?

Dunno, a MVP might not have to.

5. What is the weight benefit ratio from a users perspective?

It seems that DRY is the philosophy/religion of hpack, so these are higher goals that cannot be judged just by mundane economic calculations... :D

andreasabel avatar Apr 04 '22 19:04 andreasabel

@andreasabel, main-is: Main is not accepted by Cabal (at least, with modern versions) - I suspect that was a bug that has been fixed.

@sol, main-is: Main.hs for an executable seems to me to be a sensible default, and consistent with the DRY philosophy. If you were to give it the green light, I would have a go at implementing it.

mpilgrem avatar Aug 20 '24 22:08 mpilgrem

@mpilgrem would you be ok to do a proof of concept before I make a final call?

Things I would like to have answered

Dogfeed it on hpack itself

https://github.com/sol/hpack/blob/bb472cce37d477c8d4dd619d22cdbb4f956c3e82/package.yaml#L57

Presumably we can remove this line. Is that an improvement?

What error messages does Cabal produce if there is no Main.hs

https://github.com/sol/hpack/blob/bb472cce37d477c8d4dd619d22cdbb4f956c3e82/package.yaml#L65

What does Cabal feedback to the user if you remove this line?

sol avatar Aug 21 '24 00:08 sol

Even with this questions answered I'm still 50-50.

Hpack does not promote conventions. That's the reason why we e.g. don't default source-dirs to src. So the question is how far are we getting into "conventions" territory here?

NB: Note that personally I think conventions can be a good thing, and the defaults mechanism of hpack can be used to encode conventions. But promoting a particular set of conventions is not part of Hpack's mission.

sol avatar Aug 21 '24 01:08 sol

Hpack does not promote conventions.

I guess this should be added to the design principles. Something along the lines of "Hpack is universal. It does not promote any particular set of conventions.".

sol avatar Aug 21 '24 01:08 sol

On error messages:

  • No main-is (required since Cabal 1.0)

    Cabal (the library) complains that No 'main-is' field found for executable foo-exe

  • main-is: Main.hs, no Main.hs

    Cabal complains that can't find source for Main in . (or whatever directory)

  • main-is: Main.hs, no main exported by Main in Main.hs

    GHC complains that The IO action ‘main’ is not exported by module ‘Main’

  • main-is: Foo.hs, main exported by module Foo in Foo.hs

    GHC complains that Output was redirected with -o, but no output will be generated. There is no module named ‘Main’.

mpilgrem avatar Aug 22 '24 20:08 mpilgrem