{-# LANGUAGE TypeApplications #-}
module Control.Concurrent.Counter.Lifted.IO
( Counter
, new
, get
, set
, cas
, add
, sub
, and
, or
, xor
, nand
) where
import Prelude hiding (and, or)
import Data.Coerce
import GHC.Exts (RealWorld)
import GHC.IO
import GHC.ST
import qualified Control.Concurrent.Counter.Lifted.ST as Lifted
newtype Counter = Counter (Lifted.Counter RealWorld)
instance Eq Counter where
== :: Counter -> Counter -> Bool
(==) = (Counter RealWorld -> Counter RealWorld -> Bool)
-> Counter -> Counter -> Bool
forall a b. Coercible a b => a -> b
coerce (forall a. Eq a => a -> a -> Bool
(==) @(Lifted.Counter RealWorld))
{-# INLINE new #-}
new :: Int -> IO Counter
new :: Int -> IO Counter
new = IO (Counter RealWorld) -> IO Counter
forall a b. Coercible a b => a -> b
coerce (IO (Counter RealWorld) -> IO Counter)
-> (Int -> IO (Counter RealWorld)) -> Int -> IO Counter
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ST RealWorld (Counter RealWorld) -> IO (Counter RealWorld)
forall a. ST RealWorld a -> IO a
stToIO (ST RealWorld (Counter RealWorld) -> IO (Counter RealWorld))
-> (Int -> ST RealWorld (Counter RealWorld))
-> Int
-> IO (Counter RealWorld)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ST RealWorld (Counter RealWorld)
forall s. Int -> ST s (Counter s)
Lifted.new
{-# INLINE get #-}
get :: Counter -> IO Int
get :: Counter -> IO Int
get = (Counter RealWorld -> ST RealWorld Int) -> Counter -> IO Int
forall a b. Coercible a b => a -> b
coerce Counter RealWorld -> ST RealWorld Int
forall s. Counter s -> ST s Int
Lifted.get
{-# INLINE set #-}
set :: Counter -> Int -> IO ()
set :: Counter -> Int -> IO ()
set = (Counter RealWorld -> Int -> ST RealWorld ())
-> Counter -> Int -> IO ()
forall a b. Coercible a b => a -> b
coerce Counter RealWorld -> Int -> ST RealWorld ()
forall s. Counter s -> Int -> ST s ()
Lifted.set
{-# INLINE cas #-}
cas
:: Counter
-> Int
-> Int
-> IO Int
cas :: Counter -> Int -> Int -> IO Int
cas = (Counter RealWorld -> Int -> Int -> ST RealWorld Int)
-> Counter -> Int -> Int -> IO Int
forall a b. Coercible a b => a -> b
coerce Counter RealWorld -> Int -> Int -> ST RealWorld Int
forall s. Counter s -> Int -> Int -> ST s Int
Lifted.cas
{-# INLINE add #-}
add :: Counter -> Int -> IO Int
add :: Counter -> Int -> IO Int
add = (Counter RealWorld -> Int -> ST RealWorld Int)
-> Counter -> Int -> IO Int
forall a b. Coercible a b => a -> b
coerce Counter RealWorld -> Int -> ST RealWorld Int
forall s. Counter s -> Int -> ST s Int
Lifted.add
{-# INLINE sub #-}
sub :: Counter -> Int -> IO Int
sub :: Counter -> Int -> IO Int
sub = (Counter RealWorld -> Int -> ST RealWorld Int)
-> Counter -> Int -> IO Int
forall a b. Coercible a b => a -> b
coerce Counter RealWorld -> Int -> ST RealWorld Int
forall s. Counter s -> Int -> ST s Int
Lifted.sub
{-# INLINE and #-}
and :: Counter -> Int -> IO Int
and :: Counter -> Int -> IO Int
and = (Counter RealWorld -> Int -> ST RealWorld Int)
-> Counter -> Int -> IO Int
forall a b. Coercible a b => a -> b
coerce Counter RealWorld -> Int -> ST RealWorld Int
forall s. Counter s -> Int -> ST s Int
Lifted.and
{-# INLINE or #-}
or :: Counter -> Int -> IO Int
or :: Counter -> Int -> IO Int
or = (Counter RealWorld -> Int -> ST RealWorld Int)
-> Counter -> Int -> IO Int
forall a b. Coercible a b => a -> b
coerce Counter RealWorld -> Int -> ST RealWorld Int
forall s. Counter s -> Int -> ST s Int
Lifted.or
{-# INLINE xor #-}
xor :: Counter -> Int -> IO Int
xor :: Counter -> Int -> IO Int
xor = (Counter RealWorld -> Int -> ST RealWorld Int)
-> Counter -> Int -> IO Int
forall a b. Coercible a b => a -> b
coerce Counter RealWorld -> Int -> ST RealWorld Int
forall s. Counter s -> Int -> ST s Int
Lifted.xor
{-# INLINE nand #-}
nand :: Counter -> Int -> IO Int
nand :: Counter -> Int -> IO Int
nand = (Counter RealWorld -> Int -> ST RealWorld Int)
-> Counter -> Int -> IO Int
forall a b. Coercible a b => a -> b
coerce Counter RealWorld -> Int -> ST RealWorld Int
forall s. Counter s -> Int -> ST s Int
Lifted.nand