[Haskell-beginners] Equality instance for lists

Brandon Allbery allbery.b at gmail.com
Sat Nov 30 23:01:14 UTC 2013


On Sat, Nov 30, 2013 at 5:40 PM, Patrick Browne <patrick.browne at dit.ie>wrote:

> I am trying to write my own simplified class and instances for equality.
> I have trouble with the equality equation for the empty list.
> Even though I can use the [] == [] at the GHCi prompt I cannot use it in
> my equality test.
> How can I make my eq test handle empty lists while staying within the
> context of my current code?.
>

You can't unless you include an Eq constraint on a, since Eq is what
"defines" (==). In your other instance, you use Int and Int has an Eq
instance.

ghci can do it because of extended defaulting: it uses () for a, and there
is an Eq instance for (). But this would not help you in an instance
definition.

-- 
brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20131130/3bc1d6b0/attachment.html>


More information about the Beginners mailing list