[Haskell-cafe] New Eq instance

Bayley, Alistair Alistair_Bayley at invescoperpetual.co.uk
Thu Aug 9 10:11:05 EDT 2007

> From: haskell-cafe-bounces at haskell.org 
> [mailto:haskell-cafe-bounces at haskell.org] On Behalf Of 
> rodrigo.bonifacio
> data Step = Step Id Scenario Action State Response
> How can I define Step as an "Eq Instance", in such way that 
> two steps are equals if they have the same Id (Id is defined 
> as a synonimous for the String type).
> I tried the following code, but something is wrong....
> instance Eq Step where 
>   Step id1 scenario1 action1 state1 response1 == Step id2 
> scenario2 action2 state2 response2 = id == id
>   _ == _ = False

What error messages are you getting?

Anyway, you have the right idea, you just need a bit of cleaning up and
correct syntax. As I don't have your definitions for Scenario, Action,
etc, I'll just ignore them (we don't need them for your Eq anyway):

> data Step = Step String String
> instance Eq Step where 
>   Step id1 _ == Step id2 _ = id1 == id2

 - the _ == _ case will never be reached (AFAICT)
 - I assume " = id == id" is a typo, and that you intended "id1 == id2"

Confidentiality Note: The information contained in this message,
and any attachments, may contain confidential and/or privileged
material. It is intended solely for the person(s) or entity to
which it is addressed. Any review, retransmission, dissemination,
or taking of any action in reliance upon this information by
persons or entities other than the intended recipient(s) is
prohibited. If you received this in error, please contact the
sender and delete the material from any computer.

More information about the Haskell-Cafe mailing list