[Haskell-cafe] Proposal: deriving ShallowEq?

Bernard Pope bjpop at cs.mu.OZ.AU
Tue Jul 19 03:31:53 EDT 2005


On Tue, 2005-07-19 at 17:01 +1000, Ben Lippmeier wrote:
> Hello,
> 
> I often find it useful to determine whether two objects are using the 
> same constructor, without worrying about the constructors' arguments.

[snip]

> Having some sort of generic shallowEq operator reduces the need for a 
> host of predicates such as: (this one from Data.Maybe)
> 
>  > isJust x
>  >  = case x of
>  >	Just {}	-> True
>  >	_	-> False
> 
> .. which is an approach that is obviously going to be tedious when the 
> size of the data type becomes large.
> 
> --
> There is way to hack together a partial implementation of the ShallowEq 
> class within GHC, but it leaves much to be desired:
> 
>  > instance Show a => ShallowEq a where
>  >  (=@=) a b
>  >	= (head $ words $ show a) == (head $ words $ show b)

Ouch!

> Questions:
>   1) Does anyone know a better/existing way to implement ShallowEq that 
> doesn't involve enumerating all the constructors in the data type?
> 
>   2) If not, can anyone think of reasons why it wouldn't be a good idea 
> for GHC to derive ShallowEq (by expanding said enumeration)?

DriFT comes to mind:

   http://repetae.net/john/computer/haskell/DrIFT/

it already supplies some query operators that might make shallowEq
redundant. 

Cheers,
Bernie.



More information about the Haskell-Cafe mailing list