Skip to content

Incomplete pattern warnings with GADTs

{-
  With GADTs, -fwarn-incomplete-patterns complains
about missing
  impossible cases.
-}

{-# OPTIONS_GHC -fglasgow-exts
-fwarn-incomplete-patterns #-}

data Var = Var
data Typ = Typ

data Tree a where
   V       :: String -> Tree Var
   T_int   :: Tree Typ

getId :: Tree Var -> String
getId (V x) = x
--getId T_int = "T_int"

{-

With the last line commented out:

gadt-pattern-warning.hs:11:0:
    Warning: Pattern match(es) are non-exhaustive
             In the definition of `getId': Patterns not
matched: T_int
Ok, modules loaded: Main.


With the last line not commented out:
gadt-pattern-warning.hs:12:6:
    Inaccessible case alternative: Can't match types
`Typ' and `Var'
    When checking the pattern: T_int
    In the definition of `getId': getId T_int = "T_int"
Failed, modules loaded: none.

-}
Edited by Simon Marlow
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information