On Sun, Feb 11, 2018 at 5:14 AM, David Feuer <david.feuer@gmail.com> wrote:
Can I use reallyUnsafePtrEquality# reliably to identify whether a value is a nullary constructor of a particular type? For example, if I have

data Foo = Foo

Can I write

isFoo :: a -> Bool
isFoo !a = isTrue# (reallyUnsafePtrEquality# a Foo)

You mean like this? https://github.com/gregorycollins/hashtables/blob/master/src/Data/HashTable/Internal/UnsafeTricks.hs#L72

My experience is that this works, except when doing coverage, where the compiler adds instrumentation code that breaks the technique. I #ifdef'd my way around the problem, swapping out a slower impl when I was doing code coverage.

Greg