2

I'm learning Haskell and I've been given following assignment - I have a newtype consisting of two mixed data types, and I have to make it an instance of Eq without using deriving. Here's what I have:

data Number = One | Two | Three deriving Eq
data Character = A | B | C deriving Eq
newtype Combo = Combo ((Character, Character),(Number, Number))

instance Eq Combo where
    Combo ((a1, a2),(x1,x2)) == Combo ((b1, b2),(y1, y2)) = (a1 == b1) && (a2 == b2) && (x1 == y1) && (x2 == y2)

However, Hugs goes all

ERROR "testing.hs":5 - Ambiguous class occurrence "Eq"
*** Could refer to: Hugs.Prelude.Eq Main.Eq Main.Eq Main.Eq Main.Eq Main.Eq 

How do I fix this? I can't really import Eq hiding something either since I need it to check if a given member of Number or Character is equal.

duplode
  • 33,731
  • 7
  • 79
  • 150
skulpt
  • 527
  • 2
  • 6
  • 25
  • 6
    If that's really all code you have, then it might be a bug in Hugs. Also, please note that Hugs is no longer in development. –  Nov 18 '15 at 16:14
  • Yeah, but I have to use it, unfortunately. – skulpt Nov 18 '15 at 16:19
  • 1
    are you sure you have not redefined `class Eq` somewhere in your file (or the grader ... oh wait it's FP101x right? So it probably has no grader) – Random Dev Nov 18 '15 at 16:22
  • 1
    btw: there is probably an `Eq` instance for 2-tuples already so you could make this a bit shorter ... something like `Combo c == Combo c' = c == c'` ;) – Random Dev Nov 18 '15 at 16:24

1 Answers1

3

Changing

instance Eq Combo where
Combo ((a1, a2),(x1,x2)) == Combo ((b1, b2),(y1, y2)) = (a1 == b1) && (a2 == b2) && (x1 == y1) && (x2 == y2)

to

instance Main.Eq Combo where
Combo ((a1, a2),(x1,x2)) == Combo ((b1, b2),(y1, y2)) = (a1 == b1) && (a2 == b2) && (x1 == y1) && (x2 == y2)

apparently fixed that error.

skulpt
  • 527
  • 2
  • 6
  • 25