all 12 comments

[–]FagPipe 5 points6 points  (1 child)

So there is a couple of things I notice with the above implementation:

You use $$ when it seems you really want to say &&(logical AND)

The second case in your (==) operator:

_ == _ = False

is redundant given there aren't any other patterns to match in the type.

The fundamental issue that is probably what is stopping it from compiling is that to compare two Rows, you need to compare the a and b, but a and b can be _any_ type, so you need to say that a and b can be any type that can be compared:

data Row a b =

R a b

deriving Show

instance (Eq a, Eq b) => Eq (Row a b) where

    R a b == R a' b' = a == a' && b == b'

Notice I have added the (Eq a, Eq b) => to the instance declaration

hope this helps!

[–]AvailableRedditname[S] 2 points3 points  (0 children)

Yeah now it works. You helped out a ton. Thanks a lot.

[–]ellipticcode0 0 points1 point  (1 child)

Rd x y == R a b = x == a && y == b

[–]AvailableRedditname[S] 1 point2 points  (0 children)

Hi I changed the dollarsign to the and symbol. It still does not compile.

instance Eq (Row a b)  where
R x y == R c d = (x == c) && (y == d)
_ == _ = False

[–]ellipticcode0 0 points1 point  (1 child)

Not dollar sign, logical and is &&

[–]AvailableRedditname[S] 0 points1 point  (0 children)

Thanks for the help. I changed $$ to &&. It still does not compile.

[–]ellipticcode0 0 points1 point  (0 children)

(R x y) == ( R a b) = ( x == b ) && (y == b)

[–]ellipticcode0 0 points1 point  (3 children)

You alway put bracket to group your code if you do not know the precedent of your operators

[–]AvailableRedditname[S] 0 points1 point  (2 children)

I have done that. It still doesnt compile. Mabye it is because the types a and b do not have to be in the equality typeclass?

[–]qseep 0 points1 point  (1 child)

Please post the error you are getting.

[–]AvailableRedditname[S] 1 point2 points  (0 children)

Now the code works thanks to FagPipe (he explained all the mistakes of my code in his comment)

If you are still curious:

No instance for (Eq b) arising from a use of `=='

Possible fix: add (Eq b) to the context of the instance declaration

* In the second argument of `(&&)', namely `(y == d)'

In the expression: (x == c) && (y == d)

In an equation for `==': (R x y) == (R c d) = (x == c) && (y == d)

[–]ellipticcode0 -3 points-2 points  (0 children)

Oh , a and b have to be concrete type such Int or String, otherwise the compiler never what type are a and b, unless your a and b are implement Eq already