[Haskell-cafe] Pointer equality for nullary constructors
David Feuer
david.feuer at gmail.com
Sun Feb 11 10:14:07 UTC 2018
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)
instead of
isFoo :: forall a. Typeable a => a -> Bool
isFoo a
| Just Refl <- eqTypeRep (typeRep @a) (typeRep @Foo)
, Foo <- a
= True
| otherwise = False
The reason I'm asking is because this would let me (potentially) raiseIO# a
nullary constructor and then catch# it and see if it was what I was looking
for rather than having to open a SomeException to get to an Exception
dictionary, open that to get a TypeRep, and then peer inside that to check
a Fingerprint. That is, I'd get lighter-weight exceptions that only carry
the information I actually need.
Thanks,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180211/6850dc46/attachment.html>
More information about the Haskell-Cafe
mailing list