Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default main to Main in executables #436

Open
andreasabel opened this issue Feb 18, 2021 · 8 comments
Open

Default main to Main in executables #436

andreasabel opened this issue Feb 18, 2021 · 8 comments

Comments

@andreasabel
Copy link
Contributor

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
Copy link
Contributor Author

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

@sol
Copy link
Owner

sol commented Apr 4, 2022

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?

@andreasabel
Copy link
Contributor Author

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

@mpilgrem
Copy link
Collaborator

@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.

@sol
Copy link
Owner

sol commented Aug 21, 2024

@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

main: Main.hs

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

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

main: Spec.hs

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

@sol
Copy link
Owner

sol commented Aug 21, 2024

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
Copy link
Owner

sol commented Aug 21, 2024

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.".

@mpilgrem
Copy link
Collaborator

mpilgrem commented Aug 22, 2024

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’.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants