hpack
hpack copied to clipboard
Default `main` to `Main` in `executables`
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.
@sol: Is this a feature you would want / accept?
For me there are a couple of open questions that I currently don't have the time to look into (none exhaustive):
- There can be multiple executable sections. How would you handle this.
- What exactly is the difference between
MainandMain.hs. We already overload the meaning ofmain. - How to handle conditionals?
- Would you want to look at the file system at all?
- What is the weight benefit ratio from a users perspective?
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, 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 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?
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.
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.".
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, noMain.hsCabal complains that
can't find source for Main in .(or whatever directory) -
main-is: Main.hs, nomainexported byMaininMain.hsGHC complains that
The IO action ‘main’ is not exported by module ‘Main’ -
main-is: Foo.hs,mainexported by moduleFooinFoo.hsGHC complains that
Output was redirected with -o, but no output will be generated. There is no module named ‘Main’.