I am just learning Haskell and still trying to figure out how things work.
So, I am creating a list class that can contain a mixture of Int and Char .
data Algebra = Empty | Nmbr Int Algebra | Smbl Char Algebra
Then I try to make it an instance of Eq
instance Eq Algebra where Empty == Empty = True (Nmbr x xl) == (Nmbr y yl) = (x == y) && (xl==yl) (Smbl x xl) == (Smbl y yl) = (x == y) && (xl==yl) _ == _ = False
and I get Ambiguous occurrence == compilation error. It cannot determine the difference between Main.== and Prelude.== . If I manually replaced everything == with Main.== or Prelude.== , then it compiles fine.
I donβt understand why the compiler has so many difficulties. x and y clearly defined as Int or Char in each case. I compared what I do with numerous sample tutorials (e.g. http://www.haskell.org/tutorial/classes.html ), and I cannot determine why the compiler is such a jerk in this situation: P
source share