{-# language MagicHash #-}
{-# language UnboxedTuples #-}
module Data.Primitive.StableName
( StableName(..)
, makeStableName
, eqStableName
) where
import GHC.Exts (StableName#,isTrue#,eqStableName#,makeStableName#,unsafeCoerce#)
import Control.Monad.Primitive (PrimMonad(PrimState,primitive))
data StableName s a = StableName (StableName# a)
instance Eq (StableName s a) where
(==) = eqStableName
{-# inline (==) #-}
makeStableName :: PrimMonad m => a -> m (StableName (PrimState m) a)
makeStableName a = primitive $ \s ->
case makeStableName# a (unsafeCoerce# s) of
(# s', sn #) -> (# unsafeCoerce# s', StableName sn #)
{-# inline makeStableName #-}
eqStableName :: StableName s a -> StableName s b -> Bool
eqStableName (StableName sn1) (StableName sn2) = isTrue# (eqStableName# sn1 sn2)
{-# inline eqStableName #-}