module Judy.Refeable (
Refeable (..)
) where
import Foreign.StablePtr
import Foreign.Ptr
import Judy.Private
import qualified Judy.MiniGC as GC
import GHC.Exts (unsafeCoerce#)
class Refeable a where
toRef :: a -> IO Value
toRef = GC.newRef
fromRef :: Value -> IO a
fromRef = deRefStablePtr . castPtrToStablePtr . wordPtrToPtr
needGC :: a -> Bool
needGC _ = True
instance Refeable a where
instance Refeable Int where
toRef i = return $ unsafeCoerce# i
fromRef v = return $ unsafeCoerce# v
needGC _ = False