Haskell / GHC — is there any infix tag / pragma for “warn incomplete patterns”

人盡茶涼 提交于 2019-12-06 18:51:45

问题


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!


回答1:


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#]

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.



来源:https://stackoverflow.com/questions/5774603/haskell-ghc-is-there-any-infix-tag-pragma-for-warn-incomplete-patterns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!