{-# language ScopedTypeVariables #-}
{-# language TypeApplications #-}
{-# language FlexibleContexts #-}
{-# language ConstraintKinds #-}
{-# language TypeFamilies #-}
{-# language Trustworthy #-}
module Data.Const.Primitive.MutVar
( ConstMutVar
, constMutVar
, AMutVar
, readAMutVar
) where
import Control.Monad.Primitive
import Data.Coerce
import Data.Type.Coercion
import Data.Primitive.MutVar
import Data.Const.Unsafe
constMutVar :: AMutVar s p => p a -> ConstMutVar s a
constMutVar = constant
{-# inline constMutVar #-}
readAMutVar :: forall m p a. (PrimMonad m, AMutVar (PrimState m) p) => p a -> m a
readAMutVar = gcoerceWith (unsafeMutVarCoercion @(PrimState m) @p @a) $ coerce $ readMutVar @m @a
{-# inline readAMutVar #-}