skills
skills

Reputation: 327

Instance Eq at Haskell -> Non-exhaustive pattern

I am trying to declare an instance using haskell, here i have my data type:

data Classification = Aproved Int
                    | Denied
                    | Missing
                    deriving (Show)

And the instance declared:

instance Eq Classificacao where
    Denied     == Denied    = True
    Missing    == Missing   = True
    Aproved x  == Aproved y = y==x

When i try to compare the data constructors, it gives me the error Non-exhaustive pattern , if i use at GHCi Denied==Missing

What should i do? I am learning still.

Upvotes: 1

Views: 222

Answers (1)

shree.pat18
shree.pat18

Reputation: 21757

Add a final pattern match to test for any other combination of inputs as False, like so:

instance Eq Classification where
Denied     == Denied    = True
Missing    == Missing   = True
Aproved x  == Aproved y = y==x    
x == y = False

Upvotes: 10

Related Questions