Type class instance not found

Cross-post from Slack:

Hey, could someone tell me why this code snippet doesn’t work? (No type class instance was found for Data.Eq.Eq (Extended a0))

data Extended a = Finite a | Infinite
instance extendedOrd :: (Ord a) => Ord (Extended a) where
  compare (Finite x) (Finite y) = compare x y
  compare Infinite (Finite _) = GT
  compare (Finite _) Infinite = LT
  compare Infinite Infinite = EQ

Answer:

You have to implement Eq (Extended a) as well, as it’s a superclass of Ord
https://pursuit.purescript.org/packages/purescript-prelude/4.1.1/docs/Data.Ord#t:Ord

Btw, you can derive both instances. It is exactly the same as the manual implementation:

derive instance extendedEq :: (Eq a) => Eq (Extended a)derive instance extendedOrd :: (Ord a) => Ord (Extended a)

This relies on the order of the constructors in the data definition.