[Haskell-beginners] Defining an Instance of Ord
Petr Vápenka
petr.vapenka at gmail.com
Fri Jun 26 14:11:50 UTC 2015
What about using new type and sort the pair before comparing?
Dne 26.6.2015 15:56 "Matt Williams" <matt.williams45.mw at gmail.com>
napsal(a):
> Dear All,
>
> I am trying to produce a Map, where the (tricky) idea is that the key is a
> pair, (t1, t2), and the key is considered identical under ordering. Thus:
>
> (t1, t2) is the same as (t2, t1) but
> (t1, t3) is not the same as (t1,t2).
>
> This LOOKS like a equality definition. However, the Map key typeclass is
> defined as Ord, which requires me to define compare:
>
> instance Ord Edge where
> (Edge s1 _) `compare` (Edge s2 _) = s1 `compare` s2
>
> I am a bit stuck on how to use compare to define this type of eqlaity - any pointers very gratefully received.
>
> BW,
>
> Matt
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150626/e144f9a3/attachment.html>
More information about the Beginners
mailing list