Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell / GHC -- is there any infix tag / pragma for "warn incomplete patterns"

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!

like image 590
gatoatigrado Avatar asked Apr 25 '11 02:04

gatoatigrado


1 Answers

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.

like image 177
Don Stewart Avatar answered Oct 30 '22 23:10

Don Stewart