[Haskell-cafe] Defining methods generically for a class

Jeff Heard jefferson.r.heard at gmail.com
Thu Jan 8 12:28:14 EST 2009


That's probably the best thing to do, yes.  The purpose of doing so
was for Data.List.delete, but I see now there's a Data.List.deleteBy,
so I can use the regionEquals function as my equality predicate.

On Thu, Jan 8, 2009 at 12:26 PM, Martijn van Steenbergen
<martijn at van.steenbergen.nl> wrote:
> Hi Jeff,
>
> Jeff Heard wrote:
>>
>> instance Region a => Eq a where
>>  regiona == regionb = all $ zipWith (==)  (bounds regiona) (bounds
>> regionb)
>
> If you want to be Haskell98 compliant, why not define regionEquals :: Region
> a => a -> a -> Bool as above and use that everywhere instead of (==)?
>
> If you insist on using the overloaded (==), then in Haskell98 you will need
> to define individual Eq instances for all your custom region types. However,
> you can simply define (==) = regionEquals for all those types.
>
> Hope this helps,
>
> Martijn.
>


More information about the Haskell-Cafe mailing list