Found part of my answer: GHC.Exts exports reallyUnsafePtrEquality : a -> a -> #Int with appropriate warnings. I still wish I could use an object's address to calculate an unsound hash code but this is a good start
There's are data structures in automated reasoning (such as BDDs) that can be implemented quite efficiently in C / C++ because of the kind of pointer trick that I mentioned but in higher level languages such as ML and Haskell, we systematically lose orders of magnitude in performance. I'm trying to see how to use the pointer tricks in pure functional languages and prove that we still have referential transparency.
Hi All! Is there a way (probably an unsafe primitive) to get the address of an object in Haskell? I'd like to use it to optimize search in a cache
Found part of my answer:
GHC.Exts
exportsreallyUnsafePtrEquality : a -> a -> #Int
with appropriate warnings. I still wish I could use an object's address to calculate an unsound hash code but this is a good startanyToAddr# :: a -> State# RealWorld -> (#State# RealWorld, Addr##)
might also fit the billNice! Thanks! I assume I would take the
RealWorld
from inside theIO
monad, right?Yeah, that would be my guess!
Ah and now I see
addr2Int# :: Addr# -> Int#
if I want to use it to calculate a hashcan you be more specific about your problem? this strikes me as almost certainly the wrong approach!
There's are data structures in automated reasoning (such as BDDs) that can be implemented quite efficiently in C / C++ because of the kind of pointer trick that I mentioned but in higher level languages such as ML and Haskell, we systematically lose orders of magnitude in performance. I'm trying to see how to use the pointer tricks in pure functional languages and prove that we still have referential transparency.
If you're working on what I think you're working on I hope you'll find the time and energy to write about your findings. :surprise:
No worries, I started writing already. I have a bunch of my examples already implemented in Lean. I'll show you when I have something readable
I actually managed to write an address-based hashmap in Haskell too. It was a pleasant surprise
Awesome!