Re: [Haskell-cafe] Defining methods generically for a class

2009-01-08 Thread Jeff Heard
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
 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.
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Fwd: [Haskell-cafe] Defining methods generically for a class

2009-01-08 Thread Jeff Heard
-- Forwarded message --
From: Jeff Heard 
Date: Thu, Jan 8, 2009 at 12:26 PM
Subject: Re: [Haskell-cafe] Defining methods generically for a class
To: Cristiano Paris 


Not really...  I'm not testing if each of the items a are equal, but
rather that in the context of them being a Region, they are equal.As
long "dim" (which is in the class) can be defined, then equality is
defined over all types Region.

On Thu, Jan 8, 2009 at 12:16 PM, Cristiano Paris  wrote:
> On Thu, Jan 8, 2009 at 6:04 PM, Jeff Heard  
> wrote:
>> ...
>> How do I declare all Regions to be Eqs without putting it in the class
>> body (since I define a function over all Regions that is independent
>> of datatype that is an instance of Region)?
>
> Would this be a solution?
>
> class Eq a => Region a where
>  ...
>
> Cristiano
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Defining methods generically for a class

2009-01-08 Thread Martijn van Steenbergen

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.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Defining methods generically for a class

2009-01-08 Thread Cristiano Paris
On Thu, Jan 8, 2009 at 6:04 PM, Jeff Heard  wrote:
> ...
> How do I declare all Regions to be Eqs without putting it in the class
> body (since I define a function over all Regions that is independent
> of datatype that is an instance of Region)?

Would this be a solution?

class Eq a => Region a where
  ...

Cristiano
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Defining methods generically for a class

2009-01-08 Thread Jeff Heard
I have the following class:

class Region a where
numDimensions :: a -> Int
dim :: Int -> a -> (Double,Double)
merge :: a -> a -> a

and several ancillary methods defined, the most importance of which is:

bounds :: Region a => a -> [(Double,Double)]
bounds r = take (numDimensions r) . map dim . iterate (+1) $ 0

Let's say that I want all Regions to also be of class Eq, where

regiona == regionb = all $ zipWith (==)  (bounds regiona) (bounds regionb)

How do I declare all Regions to be Eqs without putting it in the class
body (since I define a function over all Regions that is independent
of datatype that is an instance of Region)?  Is it merely:

instance Region a => Eq a where
  regiona == regionb = all $ zipWith (==)  (bounds regiona) (bounds regionb)

-- Jeff
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe