-
Notifications
You must be signed in to change notification settings - Fork 105
Complete documentation of Hpack's main
field
#609
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://gitlab.haskell.org/ghc/ghc/-/issues/13801 limits the utility of this feature quite a bit.
Indeed, because of this limitations I myself rarely use this feature at all.
I am not sure if this feature is ready for mass consumption until the corresponding GHC issue is resolved.
@mpilgrem do you still think it is useful to document this, or should we keep this PR open until the corresponding GHC issue is resolved? If you want to get this merged now, do you think this needs a disclaimer of some sort?
|
||
Hpack's `main` field accepts a module name, a qualified name or a source file | ||
name. Hpack assumes that anything that does not have the format of the first two | ||
possibilities is a source file name. For the first two possibilities, Hpack |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not entirely accurate. Foo.hs
is a valid qualified name. However, we interpreted as a file name.
It's roughly:
- If it looks like a Haskell source file (ends in
.hs
or.lhs
), we interpret it as a file path. - If it is a valid qualified name, we take it as a qualified name.
- If it is a valid module name, we take it as a module name.
- As a fallback we take it as a file path.
Or in other words, Hpack does not accept entry points named hs
or lhs
.
Lines 55 to 61 in e11cf4f
parseMain :: String -> (FilePath, [GhcOption]) | |
parseMain main = case reverse name of | |
x : _ | isQualifiedIdentifier name && x `notElem` ["hs", "lhs"] -> (intercalate "/" (init name) ++ ".hs", ["-main-is " ++ main]) | |
_ | isModule name -> (intercalate "/" name ++ ".hs", ["-main-is " ++ main]) | |
_ -> (main, []) | |
where | |
name = splitOn '.' main |
|
||
By convention, a Haskell program must have a module called `Main` which exports | ||
an IO action named `main`. When the program is executed, the action is | ||
performed. However, GHC's `main-is` option can be used to change the name of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
performed. However, GHC's `main-is` option can be used to change the name of the | |
performed. However, GHC's `-main-is` option can be used to change the name of the |
|
||
executable my-app | ||
main-is: MyMainModule.hs | ||
ghc-options: -main-is MyMainModule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't frequently document things in terms of how they desugar to .cabal
syntax. Rather we document how they can be used, so that a user does not need to be familiar with Cabal to be able to use Hpack.
I'm not saying this is necessarily bad, just want to bring it up.
Motivation, @sol's currently undocumented explanation at:
main-is
field (source file) does not alter GHC's-main-is
option (module and function name) commercialhaskell/stack#6695 (comment)Points of reference:
-main-is
; andmain-is
field.Unusually, for Hpack's approach to its README, I have added three short sentences of introductory context boiled down from the Haskell 2010 Language Report and the GHC User's Guide. That is because the scope for confusion is high.