for the record, SYB's toConstr throws for function types.
Ralf
-Original Message-
From: [EMAIL PROTECTED] [mailto:haskell-cafe-
[EMAIL PROTECTED] On Behalf Of Ben Lippmeier
Sent: Tuesday, July 19, 2005 8:56 PM
Cc: haskell-cafe@haskell.org
Subject: Re: [Haskell-cafe] Proposal: deriving
Ben,
I often find it useful to determine whether two objects are using the
same constructor, without worrying about the constructors' arguments.
In Generic Haskell, you can define shallowEq, well ;), generically:
shallowEq {| a :: * |} :: (shallowEq {| a |}) = a - a - Bool
shallowEq {|
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
On Tue, 19 Jul 2005, Ben Lippmeier wrote:
An example, using some arbitrary data type Thingo:
class ShallowEq a where
shallowEq :: a - a - Bool
data Thingo a b
= TOne a
| TTwo a b Int Char Float
| TThree Int Char b b
Questions:
1) Does anyone know a
Hello Ben,
Tuesday, July 19, 2005, 11:01:32 AM, you wrote:
BL I often find it useful to determine whether two objects are using the
BL same constructor, without worrying about the constructors' arguments.
BL There is way to hack together a partial implementation of the ShallowEq
BL class within
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
: [Haskell-cafe] Proposal: deriving ShallowEq?
Hello Ben,
Tuesday, July 19, 2005, 11:01:32 AM, you wrote:
BL I often find it useful to determine whether two objects are using
the
BL same constructor, without worrying about the constructors'
arguments.
BL There is way to hack together a partial
Ralf Lammel wrote:
As Bulat points out, the GHC primitive dataToTag#
indeed nicely solves the problem. Ben, just for
completeness' sake; with SYB, you get such reflective
information too (and others):
shallowEq :: Data a = a - a - Bool
shallowEq x y = toConstr x == toConstr y
(dataToTag#