[Haskell-cafe] Proposal: deriving ShallowEq?
Remi Turk
rturk at science.uva.nl
Tue Jul 19 08:26:17 EDT 2005
On Tue, Jul 19, 2005 at 08:16:35PM +1000, Ben Lippmeier wrote:
> Bulat Ziganshin wrote:
>
> >reading GHC sources is always very interesting :)
> >that is from GHC/Base.hs :
>
> >getTag :: a -> Int#
> >getTag x = x `seq` dataToTag# x
>
> ! This is just what I was looking for, thankyou.
>
> My shallowEq function is now simply:
>
> shallowEq :: a -> a -> Bool
> shallowEq a b = getTag a ==# getTag b
>
> My project is already totally reliant on GHC, and this will save me the
> heartache of hacking DrIFT (which I was in the process of setting up
> when I saw this mail) into my makefile.
>
> Portability be damned!
>
> Ben.
You might increase portability a bit by using
import Data.Generics
shallowEq :: Data a => a -> a -> Bool
shallowEq x y = toConstr x == toConstr y
it does introduce a dependency on Data though
Groeten,
Remi
--
Nobody can be exactly like me. Even I have trouble doing it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20050719/d4691ed7/attachment.bin
More information about the Haskell-Cafe
mailing list