Haskell / GHC - 是否有任何中缀标签/杂注用于“警告不完整模式” [英] Haskell / GHC -- is there any infix tag / pragma for "warn incomplete patterns"

查看:128
本文介绍了Haskell / GHC - 是否有任何中缀标签/杂注用于“警告不完整模式”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个会在特定的不完整模式中发出警告的编译指示。它会使编译器失败,出现以下(假设)代码:

I'm looking for a pragma that will warn on a particular incomplete pattern. It would make the compiler fail with the following (hypothetical) code:

{-# FAILIF incomplete-patterns #-}
f :: Int -> Int
f 0 = 0

我试图用箭头编写一个编译器,知道模式匹配完成将有助于隔离错误。感谢!

I am trying to write a "compiler" using Arrows, and knowing pattern matching is complete would help isolate bugs. Thanks!

推荐答案

您可以使用 -Wall

You can require warnings, including incomplete patterns, with -Wall:

{-# OPTIONS_GHC -Wall #-}

module A where

f :: Int -> Int
f 0 = 0

收益率:

Yielding:

A.hs:6:1:
Warning: Pattern match(es) are non-exhaustive
     In an equation for `f':
         Patterns not matched: GHC.Types.I# #x with #x `notElem` [0#]

或者更具体地说, -fwarn-incomplete-patterns 取代 -Wall

Or more specifically, with -fwarn-incomplete-patterns inplace of -Wall.

没有什么东西可以在每个表达式的基础上工作:目前您仅限于每个模块。

There's nothing that will work on a per-expression basis: you're currently restricted to a per-module basis.

这篇关于Haskell / GHC - 是否有任何中缀标签/杂注用于“警告不完整模式”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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