You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让VSCode中的Haskero提示非穷尽模式匹配警告?

Fixing Missing Compiler Warnings in Haskero for VS Code

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:
    stack install ghc-mod
    
    or
    cabal 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:12:17