[Haskell-cafe] Pointer equality for nullary constructors

Gregory Collins greg at gregorycollins.net
Tue Feb 20 22:56:19 UTC 2018

On Sun, Feb 11, 2018 at 5:14 AM, David Feuer <david.feuer at 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?

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180220/e5c4d903/attachment.html>

More information about the Haskell-Cafe mailing list