如何让Haskero在非穷举模式匹配中发出警告 [英] How to get Haskero to warn on non-exhaustive pattern matches

查看:106
本文介绍了如何让Haskero在非穷举模式匹配中发出警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在 Visual Studio代码中评估 Haskero 作为替代的Haskell编辑器,而不是 Atom-Haskell Atom >.到目前为止, Haskero 似乎很有前途,但我错过了通常会从 Atom-Haskell 收到的编译器警告.

I'm currently evaluating Haskero in Visual Studio Code as an alternative Haskell editor instead of Atom with Atom-Haskell. So far, Haskero seems promising, but I miss the compiler warnings I'd usually get from Atom-Haskell.

作为说明问题的一种方法,请考虑以下简单再现:

As a way to illustrate the problem, consider this simple repro:

  1. 在已安装 Haskero 的情况下打开 Visual Studio代码
  2. 添加新的Haskell文件:Repro.hs
  3. 将以下内容添加到文件中
  4. 保存
  1. Open Visual Studio Code with Haskero already installed
  2. Add a new Haskell file: Repro.hs
  3. Add the following content to the file
  4. Press Save

文件内容:

module Repro where

foo :: Maybe a -> a
foo (Just x) = x

预期的行为

编辑器应警告以下内容:

Expected behaviour

The editor should give a warning to the effect of:

Pattern match(es) are non-exhaustive
In an equation for `foo': Patterns not matched: Nothing

Atom-Haskell 完成此操作.

什么都没发生. 问题视图仅指出:

Nothing happens. The Problems view just states that:

到目前为止,尚未在工作区中检测到任何问题.

No problems have been detected in the workspace so far.

更多详细信息

上述重现步骤是我能想到的最简单的步骤,但是当我创建一个完整的Stack项目并确保已在我的根目录中运行stack build intero时,我会看到相同的(缺少)行为项目目录.

More details

The above steps to reproduce are the simplest ones I could think of, but I see the same (lack of) behaviour when I create a full Stack project and make sure that I've run stack build intero in the root of my project directory.

我的环境是:

  • Windows 10 Pro x64
  • 堆栈版本1.6.3,Git修订版b27e629b8c4ce369e3b8273f04db193b060000db(5454提交)x86_64 hpack-0.20.0
  • Visual Studio Code版本1.20.0
  • Haskero版本1.3.1
  • Atom 1.23.3 x64版本
  • 语言haskell 版本1.17.3
  • Windows 10 Pro x64
  • Stack version 1.6.3, Git revision b27e629b8c4ce369e3b8273f04db193b060000db (5454 commits) x86_64 hpack-0.20.0
  • Visual Studio Code version 1.20.0
  • Haskero version 1.3.1
  • Atom version 1.23.3 x64
  • language-haskell version 1.17.3

推荐答案

您似乎必须告诉Haskero将任何警告变为致命错误(请注意-Werror标志):

It looks like you have to tell Haskero to make any warning into a fatal error (note the -Werror flag):

"haskero.intero.ghciOptions": [
    "-Wall",
    "-Werror"
]

但是,我真的不明白为什么我们必须这样做,因为这是开箱即用的:

However, I can't really understand why we would have to do this, since this works out of the box:

stack ghci --with-ghc intero "--ghci-options=-Wall" --no-build --no-load

这似乎是Haskero在Visual Studio Code中启动Intero的方式,在GHCi中,我可以看到警告而无需通过-Werror ...

That seems to be the way Haskero launches Intero in Visual Studio Code, and in GHCi I can see the warning without passing -Werror...

出于好奇,我曾尝试使用hsdev 0.3.1.2 ,然后Sublime Haskell 91e0d29 似乎可以正常工作盒子:

Out of curiosity, I've tried the same with hsdev 0.3.1.2, and Sublime Haskell 91e0d29, and seems to be working straight out of the box:

希望有帮助.

这篇关于如何让Haskero在非穷举模式匹配中发出警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆