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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With