如何让VSCode中的Haskero提示非穷尽模式匹配警告?
Hey there! I totally get it—missing those helpful compiler warnings (like non-exhaustive pattern matches) when switching from Atom-Haskell to Haskero is super frustrating. Let’s get this sorted out with some straightforward steps:
1. Configure Your Project’s Build Settings
Haskero respects the warning flags set in your Haskell project’s config files, so start here if you’re working with a Cabal or Stack project:
For Cabal Projects
Open your .cabal file, and add warning flags to the ghc-options field under your executable/library section. The -Wall flag enables most common warnings (including non-exhaustive pattern matches), but you can add more granular flags if needed:
executable my-project -- Other existing fields... ghc-options: -Wall -Wcompat -Wincomplete-record-updates
For Stack Projects
In your stack.yaml file, add the warning flags to apply to all local packages:
ghc-options: "$locals": -Wall
2. Set Global Haskero Warning Options
If you’re working on standalone Haskell files (not part of a Cabal/Stack project), or want to enforce warnings across all projects, configure Haskero directly in VS Code:
- Open VS Code settings (press
Ctrl+,on Windows/Linux,Cmd+,on macOS) - Search for Haskero: Ghc Options
- Set the value to
["-Wall"](or add any extra warning flags you find useful)
3. Update Dependencies
Make sure you’re running the latest versions of Haskero and its underlying tools:
- Update Haskero via the VS Code Extensions panel
- If you use
ghc-mod(Haskero’s backend tool), update it with either:
orstack install ghc-modcabal install ghc-mod
4. Test It Out
Restart VS Code, then create your Repro.hs file with a non-exhaustive pattern match like this:
greet :: Bool -> String greet True = "Hello!"
Save the file—you should now see a warning highlighting the missing pattern for False.
内容的提问来源于stack exchange,提问作者Mark Seemann

