Non-exhaustive pattern match warning (incorrect?)

I'm cleaning up some old projects, and hit this: src/Octet.hs:47:27: Warning: Pattern match(es) are non-exhaustive In a record-update construct: Patterns not matched: Octet.None But in the source, I've checked for that case: class Maskable a where apply_mask :: a -> Maskbits -> Bit -> a instance Maskable Octet where apply_mask _ Maskbits.None _ = Octet.None apply_mask Octet.None _ _ = Octet.None apply_mask oct mask bit | mask == Eight = oct | mask == Seven = oct { b8 = bit } -- Line 47 ... | otherwise = Octet.None Am I overlooking something, or did I already match Octet.None?

On Mon, Dec 26, 2011 at 1:21 PM, Michael Orlitzky
I'm cleaning up some old projects, and hit this:
src/Octet.hs:47:27: Warning: Pattern match(es) are non-exhaustive In a record-update construct: Patterns not matched: Octet.None
But in the source, I've checked for that case:
class Maskable a where apply_mask :: a -> Maskbits -> Bit -> a
instance Maskable Octet where apply_mask _ Maskbits.None _ = Octet.None apply_mask Octet.None _ _ = Octet.None apply_mask oct mask bit | mask == Eight = oct | mask == Seven = oct { b8 = bit } -- Line 47 ... | otherwise = Octet.None
Am I overlooking something, or did I already match Octet.None?
What is your definition of the 'Octet' type?
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 12/26/11 13:42, Antoine Latter wrote:
Am I overlooking something, or did I already match Octet.None?
What is your definition of the 'Octet' type?
-- An Octet consists of eight bits. For our purposes, the most -- significant bit will come "first." That is, b1 is in the 2^7 -- place while b8 is in the 2^0 place. data Octet = None | Octet { b1 :: Bit, b2 :: Bit, b3 :: Bit, b4 :: Bit, b5 :: Bit, b6 :: Bit, b7 :: Bit, b8 :: Bit } deriving (Eq)

On Mon, Dec 26, 2011 at 2:19 PM, Michael Orlitzky
On 12/26/11 13:42, Antoine Latter wrote:
Am I overlooking something, or did I already match Octet.None?
What is your definition of the 'Octet' type?
-- An Octet consists of eight bits. For our purposes, the most -- significant bit will come "first." That is, b1 is in the 2^7 -- place while b8 is in the 2^0 place. data Octet = None | Octet { b1 :: Bit, b2 :: Bit, b3 :: Bit, b4 :: Bit, b5 :: Bit, b6 :: Bit, b7 :: Bit, b8 :: Bit } deriving (Eq)
The error is warning you that the record update 'oct { b8 = bit }' can fail at run-time if 'oct' is None. Since it looks like you've checked for that you shouldn't have a problem, but the compiler doesn't know that. If you decompose your type into 'Octet' without the 'None' case, and 'Maybe Octet' for the times when 'None' is appropriate, the compiler will have enough information to not give warnings like this. I can't be the one to tell you if that is worth it or not. Antoine
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 12/26/2011 03:17 PM, Antoine Latter wrote:
The error is warning you that the record update 'oct { b8 = bit }' can fail at run-time if 'oct' is None.
Since it looks like you've checked for that you shouldn't have a problem, but the compiler doesn't know that.
Thanks, that's what I thought but I wanted to make sure I wasn't missing something obvious.
If you decompose your type into 'Octet' without the 'None' case, and 'Maybe Octet' for the times when 'None' is appropriate, the compiler will have enough information to not give warnings like this.
I can't be the one to tell you if that is worth it or not.
I must have had a good reason to do it that way, right? =)
participants (2)
-
Antoine Latter
-
Michael Orlitzky