Lets say I have this program
{-# LANGUAGE GADTs #-}data My a where A :: Int -> My Int B :: Char -> My Charmain :: IO ()main = do let x = undefined :: My a case x of A v -> print v -- print x
compiles fine.
But when I comment in the print x
, I get:
gadt.hs: line 13, column 12: Couldn't match type ‘a0’ with ‘()’‘a0’ is untouchable inside the constraints (a1 ~ GHC.Types.Int) bound by a pattern with constructor Main.A :: GHC.Types.Int -> Main.My GHC.Types.Int, in a case alternative at /home/niklas/src/hs/gadt-binary.hs:13:5-7 Expected type: GHC.Types.IO a0 Actual type: GHC.Types.IO () In the expression: System.IO.print v In a case alternative: Main.A v -> System.IO.print v
Why do I get this error in line 13 (A v -> print v
) instead of only in the print x
line?
I thought the first occurrence should determine the type.
Please enlighten me :)