Copyright | (c) Justin Le 2019 |
---|---|
License | BSD3 |
Maintainer | justin@jle.im |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Abstract over different types for mutable references of values.
Synopsis
- class Monad m => Mutable m a where
- newtype MutRef a = MutRef {
- runMutRef :: a
- newtype RefFor m a = RefFor {}
- class Monad m => GMutable m f
- newtype GRef m a = GRef {}
- gThawRef :: (Generic a, GMutable m (Rep a)) => a -> m (GRef m a)
- gFreezeRef :: (Generic a, GMutable m (Rep a)) => GRef m a -> m a
- gCopyRef :: (Generic a, GMutable m (Rep a)) => GRef m a -> a -> m ()
- newtype RecRef m f a = RecRef {}
- newtype MR s n a = MR {}
- newtype ML s n k a = ML {}
- reMutable :: forall m n a r. (Mutable m a, Monad n) => (forall x. m x -> n x) -> (Mutable n a => r) -> r
- reMutableConstraint :: forall m n a. (Mutable m a, Monad n) => (forall x. m x -> n x) -> Mutable m a :- Mutable n a
- newtype ReMutable (s :: Type) m a = ReMutable a
- newtype ReMutableTrans m n = RMT {
- runRMT :: forall x. m x -> n x
Documentation
class Monad m => Mutable m a where Source #
Nothing
thawRef :: a -> m (Ref m a) Source #
freezeRef :: Ref m a -> m a Source #
copyRef :: Ref m a -> a -> m () Source #
modifyRef :: Ref m a -> (a -> a) -> m () Source #
Apply a pure function on an immutable value onto a value stored in a mutable reference.
modifyRef' :: Ref m a -> (a -> a) -> m () Source #
modifyRef
, but forces the result before storing it back in the
reference.
updateRef :: Ref m a -> (a -> (a, b)) -> m b Source #
Apply a pure function on an immutable value onto a value stored in a mutable reference, returning a result value from that function.
updateRef' :: Ref m a -> (a -> (a, b)) -> m b Source #
updateRef
, but forces the updated value before storing it back in the
reference.
thawRef :: (Ref m a ~ MutVar (PrimState m) a, PrimMonad m) => a -> m (Ref m a) Source #
freezeRef :: (Ref m a ~ MutVar (PrimState m) a, PrimMonad m) => Ref m a -> m a Source #
copyRef :: (Ref m a ~ MutVar (PrimState m) a, PrimMonad m) => Ref m a -> a -> m () Source #
Instances
Monad m => Mutable m () Source # | |
Defined in Numeric.Opto.Ref thawRef :: () -> m (Ref m ()) Source # freezeRef :: Ref m () -> m () Source # copyRef :: Ref m () -> () -> m () Source # modifyRef :: Ref m () -> (() -> ()) -> m () Source # modifyRef' :: Ref m () -> (() -> ()) -> m () Source # updateRef :: Ref m () -> (() -> ((), b)) -> m b Source # updateRef' :: Ref m () -> (() -> ((), b)) -> m b Source # | |
PrimMonad m => Mutable m Double Source # | |
Defined in Numeric.Opto.Ref thawRef :: Double -> m (Ref m Double) Source # freezeRef :: Ref m Double -> m Double Source # copyRef :: Ref m Double -> Double -> m () Source # modifyRef :: Ref m Double -> (Double -> Double) -> m () Source # modifyRef' :: Ref m Double -> (Double -> Double) -> m () Source # updateRef :: Ref m Double -> (Double -> (Double, b)) -> m b Source # updateRef' :: Ref m Double -> (Double -> (Double, b)) -> m b Source # | |
PrimMonad m => Mutable m Float Source # | |
Defined in Numeric.Opto.Ref thawRef :: Float -> m (Ref m Float) Source # freezeRef :: Ref m Float -> m Float Source # copyRef :: Ref m Float -> Float -> m () Source # modifyRef :: Ref m Float -> (Float -> Float) -> m () Source # modifyRef' :: Ref m Float -> (Float -> Float) -> m () Source # updateRef :: Ref m Float -> (Float -> (Float, b)) -> m b Source # updateRef' :: Ref m Float -> (Float -> (Float, b)) -> m b Source # | |
PrimMonad m => Mutable m Integer Source # | |
Defined in Numeric.Opto.Ref thawRef :: Integer -> m (Ref m Integer) Source # freezeRef :: Ref m Integer -> m Integer Source # copyRef :: Ref m Integer -> Integer -> m () Source # modifyRef :: Ref m Integer -> (Integer -> Integer) -> m () Source # modifyRef' :: Ref m Integer -> (Integer -> Integer) -> m () Source # updateRef :: Ref m Integer -> (Integer -> (Integer, b)) -> m b Source # updateRef' :: Ref m Integer -> (Integer -> (Integer, b)) -> m b Source # | |
PrimMonad m => Mutable m Int Source # | |
Defined in Numeric.Opto.Ref thawRef :: Int -> m (Ref m Int) Source # freezeRef :: Ref m Int -> m Int Source # copyRef :: Ref m Int -> Int -> m () Source # modifyRef :: Ref m Int -> (Int -> Int) -> m () Source # modifyRef' :: Ref m Int -> (Int -> Int) -> m () Source # updateRef :: Ref m Int -> (Int -> (Int, b)) -> m b Source # updateRef' :: Ref m Int -> (Int -> (Int, b)) -> m b Source # | |
(PrimMonad m, KnownNat n) => Mutable m (C n) Source # | |
Defined in Numeric.Opto.Ref thawRef :: C n -> m (Ref m (C n)) Source # freezeRef :: Ref m (C n) -> m (C n) Source # copyRef :: Ref m (C n) -> C n -> m () Source # modifyRef :: Ref m (C n) -> (C n -> C n) -> m () Source # modifyRef' :: Ref m (C n) -> (C n -> C n) -> m () Source # updateRef :: Ref m (C n) -> (C n -> (C n, b)) -> m b Source # updateRef' :: Ref m (C n) -> (C n -> (C n, b)) -> m b Source # | |
(PrimMonad m, KnownNat n) => Mutable m (R n) Source # | |
Defined in Numeric.Opto.Ref thawRef :: R n -> m (Ref m (R n)) Source # freezeRef :: Ref m (R n) -> m (R n) Source # copyRef :: Ref m (R n) -> R n -> m () Source # modifyRef :: Ref m (R n) -> (R n -> R n) -> m () Source # modifyRef' :: Ref m (R n) -> (R n -> R n) -> m () Source # updateRef :: Ref m (R n) -> (R n -> (R n, b)) -> m b Source # updateRef' :: Ref m (R n) -> (R n -> (R n, b)) -> m b Source # | |
(PrimMonad m, Element a) => Mutable m (Matrix a) Source # | |
Defined in Numeric.Opto.Ref thawRef :: Matrix a -> m (Ref m (Matrix a)) Source # freezeRef :: Ref m (Matrix a) -> m (Matrix a) Source # copyRef :: Ref m (Matrix a) -> Matrix a -> m () Source # modifyRef :: Ref m (Matrix a) -> (Matrix a -> Matrix a) -> m () Source # modifyRef' :: Ref m (Matrix a) -> (Matrix a -> Matrix a) -> m () Source # updateRef :: Ref m (Matrix a) -> (Matrix a -> (Matrix a, b)) -> m b Source # updateRef' :: Ref m (Matrix a) -> (Matrix a -> (Matrix a, b)) -> m b Source # | |
(PrimMonad m, Prim a) => Mutable m (Vector a) Source # | |
Defined in Numeric.Opto.Ref thawRef :: Vector a -> m (Ref m (Vector a)) Source # freezeRef :: Ref m (Vector a) -> m (Vector a) Source # copyRef :: Ref m (Vector a) -> Vector a -> m () Source # modifyRef :: Ref m (Vector a) -> (Vector a -> Vector a) -> m () Source # modifyRef' :: Ref m (Vector a) -> (Vector a -> Vector a) -> m () Source # updateRef :: Ref m (Vector a) -> (Vector a -> (Vector a, b)) -> m b Source # updateRef' :: Ref m (Vector a) -> (Vector a -> (Vector a, b)) -> m b Source # | |
(PrimMonad m, Unbox a) => Mutable m (Vector a) Source # | |
Defined in Numeric.Opto.Ref thawRef :: Vector a -> m (Ref m (Vector a)) Source # freezeRef :: Ref m (Vector a) -> m (Vector a) Source # copyRef :: Ref m (Vector a) -> Vector a -> m () Source # modifyRef :: Ref m (Vector a) -> (Vector a -> Vector a) -> m () Source # modifyRef' :: Ref m (Vector a) -> (Vector a -> Vector a) -> m () Source # updateRef :: Ref m (Vector a) -> (Vector a -> (Vector a, b)) -> m b Source # updateRef' :: Ref m (Vector a) -> (Vector a -> (Vector a, b)) -> m b Source # | |
(PrimMonad m, Storable a) => Mutable m (Vector a) Source # | |
Defined in Numeric.Opto.Ref thawRef :: Vector a -> m (Ref m (Vector a)) Source # freezeRef :: Ref m (Vector a) -> m (Vector a) Source # copyRef :: Ref m (Vector a) -> Vector a -> m () Source # modifyRef :: Ref m (Vector a) -> (Vector a -> Vector a) -> m () Source # modifyRef' :: Ref m (Vector a) -> (Vector a -> Vector a) -> m () Source # updateRef :: Ref m (Vector a) -> (Vector a -> (Vector a, b)) -> m b Source # updateRef' :: Ref m (Vector a) -> (Vector a -> (Vector a, b)) -> m b Source # | |
PrimMonad m => Mutable m (Vector a) Source # | |
Defined in Numeric.Opto.Ref thawRef :: Vector a -> m (Ref m (Vector a)) Source # freezeRef :: Ref m (Vector a) -> m (Vector a) Source # copyRef :: Ref m (Vector a) -> Vector a -> m () Source # modifyRef :: Ref m (Vector a) -> (Vector a -> Vector a) -> m () Source # modifyRef' :: Ref m (Vector a) -> (Vector a -> Vector a) -> m () Source # updateRef :: Ref m (Vector a) -> (Vector a -> (Vector a, b)) -> m b Source # updateRef' :: Ref m (Vector a) -> (Vector a -> (Vector a, b)) -> m b Source # | |
PrimMonad m => Mutable m (MutRef a) Source # | |
Defined in Numeric.Opto.Ref thawRef :: MutRef a -> m (Ref m (MutRef a)) Source # freezeRef :: Ref m (MutRef a) -> m (MutRef a) Source # copyRef :: Ref m (MutRef a) -> MutRef a -> m () Source # modifyRef :: Ref m (MutRef a) -> (MutRef a -> MutRef a) -> m () Source # modifyRef' :: Ref m (MutRef a) -> (MutRef a -> MutRef a) -> m () Source # updateRef :: Ref m (MutRef a) -> (MutRef a -> (MutRef a, b)) -> m b Source # updateRef' :: Ref m (MutRef a) -> (MutRef a -> (MutRef a, b)) -> m b Source # | |
PrimMonad m => Mutable m (Complex a) Source # | |
Defined in Numeric.Opto.Ref thawRef :: Complex a -> m (Ref m (Complex a)) Source # freezeRef :: Ref m (Complex a) -> m (Complex a) Source # copyRef :: Ref m (Complex a) -> Complex a -> m () Source # modifyRef :: Ref m (Complex a) -> (Complex a -> Complex a) -> m () Source # modifyRef' :: Ref m (Complex a) -> (Complex a -> Complex a) -> m () Source # updateRef :: Ref m (Complex a) -> (Complex a -> (Complex a, b)) -> m b Source # updateRef' :: Ref m (Complex a) -> (Complex a -> (Complex a, b)) -> m b Source # | |
PrimMonad m => Mutable m (Ratio a) Source # | |
Defined in Numeric.Opto.Ref thawRef :: Ratio a -> m (Ref m (Ratio a)) Source # freezeRef :: Ref m (Ratio a) -> m (Ratio a) Source # copyRef :: Ref m (Ratio a) -> Ratio a -> m () Source # modifyRef :: Ref m (Ratio a) -> (Ratio a -> Ratio a) -> m () Source # modifyRef' :: Ref m (Ratio a) -> (Ratio a -> Ratio a) -> m () Source # updateRef :: Ref m (Ratio a) -> (Ratio a -> (Ratio a, b)) -> m b Source # updateRef' :: Ref m (Ratio a) -> (Ratio a -> (Ratio a, b)) -> m b Source # | |
(PrimMonad m, KnownNat n, KnownNat k) => Mutable m (M n k) Source # | |
Defined in Numeric.Opto.Ref thawRef :: M n k -> m (Ref m (M n k)) Source # freezeRef :: Ref m (M n k) -> m (M n k) Source # copyRef :: Ref m (M n k) -> M n k -> m () Source # modifyRef :: Ref m (M n k) -> (M n k -> M n k) -> m () Source # modifyRef' :: Ref m (M n k) -> (M n k -> M n k) -> m () Source # updateRef :: Ref m (M n k) -> (M n k -> (M n k, b)) -> m b Source # updateRef' :: Ref m (M n k) -> (M n k -> (M n k, b)) -> m b Source # | |
(PrimMonad m, KnownNat n, KnownNat k) => Mutable m (L n k) Source # | |
Defined in Numeric.Opto.Ref thawRef :: L n k -> m (Ref m (L n k)) Source # freezeRef :: Ref m (L n k) -> m (L n k) Source # copyRef :: Ref m (L n k) -> L n k -> m () Source # modifyRef :: Ref m (L n k) -> (L n k -> L n k) -> m () Source # modifyRef' :: Ref m (L n k) -> (L n k -> L n k) -> m () Source # updateRef :: Ref m (L n k) -> (L n k -> (L n k, b)) -> m b Source # updateRef' :: Ref m (L n k) -> (L n k -> (L n k, b)) -> m b Source # | |
(Monad m, Mutable m a, Mutable m b) => Mutable m (a, b) Source # | |
Defined in Numeric.Opto.Ref thawRef :: (a, b) -> m (Ref m (a, b)) Source # freezeRef :: Ref m (a, b) -> m (a, b) Source # copyRef :: Ref m (a, b) -> (a, b) -> m () Source # modifyRef :: Ref m (a, b) -> ((a, b) -> (a, b)) -> m () Source # modifyRef' :: Ref m (a, b) -> ((a, b) -> (a, b)) -> m () Source # updateRef :: Ref m (a, b) -> ((a, b) -> ((a, b), b0)) -> m b0 Source # updateRef' :: Ref m (a, b) -> ((a, b) -> ((a, b), b0)) -> m b0 Source # | |
(Monad m, Mutable m (f a2), Mutable m (Rec f as), Ref m (Rec f as) ~ Rec (RecRef m f) as) => Mutable m (Rec f (a2 ': as)) Source # | |
Defined in Numeric.Opto.Ref thawRef :: Rec f (a2 ': as) -> m (Ref m (Rec f (a2 ': as))) Source # freezeRef :: Ref m (Rec f (a2 ': as)) -> m (Rec f (a2 ': as)) Source # copyRef :: Ref m (Rec f (a2 ': as)) -> Rec f (a2 ': as) -> m () Source # modifyRef :: Ref m (Rec f (a2 ': as)) -> (Rec f (a2 ': as) -> Rec f (a2 ': as)) -> m () Source # modifyRef' :: Ref m (Rec f (a2 ': as)) -> (Rec f (a2 ': as) -> Rec f (a2 ': as)) -> m () Source # updateRef :: Ref m (Rec f (a2 ': as)) -> (Rec f (a2 ': as) -> (Rec f (a2 ': as), b)) -> m b Source # updateRef' :: Ref m (Rec f (a2 ': as)) -> (Rec f (a2 ': as) -> (Rec f (a2 ': as), b)) -> m b Source # | |
Monad m => Mutable m (Rec f ([] :: [u])) Source # | |
Defined in Numeric.Opto.Ref thawRef :: Rec f [] -> m (Ref m (Rec f [])) Source # freezeRef :: Ref m (Rec f []) -> m (Rec f []) Source # copyRef :: Ref m (Rec f []) -> Rec f [] -> m () Source # modifyRef :: Ref m (Rec f []) -> (Rec f [] -> Rec f []) -> m () Source # modifyRef' :: Ref m (Rec f []) -> (Rec f [] -> Rec f []) -> m () Source # updateRef :: Ref m (Rec f []) -> (Rec f [] -> (Rec f [], b)) -> m b Source # updateRef' :: Ref m (Rec f []) -> (Rec f [] -> (Rec f [], b)) -> m b Source # | |
(Monad m, Mutable m a, Mutable m b, Mutable m c) => Mutable m (a, b, c) Source # | |
Defined in Numeric.Opto.Ref thawRef :: (a, b, c) -> m (Ref m (a, b, c)) Source # freezeRef :: Ref m (a, b, c) -> m (a, b, c) Source # copyRef :: Ref m (a, b, c) -> (a, b, c) -> m () Source # modifyRef :: Ref m (a, b, c) -> ((a, b, c) -> (a, b, c)) -> m () Source # modifyRef' :: Ref m (a, b, c) -> ((a, b, c) -> (a, b, c)) -> m () Source # updateRef :: Ref m (a, b, c) -> ((a, b, c) -> ((a, b, c), b0)) -> m b0 Source # updateRef' :: Ref m (a, b, c) -> ((a, b, c) -> ((a, b, c), b0)) -> m b0 Source # | |
(PrimMonad m, Vector v a) => Mutable m (Vector v n a) Source # | |
Defined in Numeric.Opto.Ref thawRef :: Vector v n a -> m (Ref m (Vector v n a)) Source # freezeRef :: Ref m (Vector v n a) -> m (Vector v n a) Source # copyRef :: Ref m (Vector v n a) -> Vector v n a -> m () Source # modifyRef :: Ref m (Vector v n a) -> (Vector v n a -> Vector v n a) -> m () Source # modifyRef' :: Ref m (Vector v n a) -> (Vector v n a -> Vector v n a) -> m () Source # updateRef :: Ref m (Vector v n a) -> (Vector v n a -> (Vector v n a, b)) -> m b Source # updateRef' :: Ref m (Vector v n a) -> (Vector v n a -> (Vector v n a, b)) -> m b Source # | |
(Monad n, Mutable m a, Reifies s (ReMutableTrans m n)) => Mutable n (ReMutable s m a) Source # | |
Defined in Numeric.Opto.Ref thawRef :: ReMutable s m a -> n (Ref n (ReMutable s m a)) Source # freezeRef :: Ref n (ReMutable s m a) -> n (ReMutable s m a) Source # copyRef :: Ref n (ReMutable s m a) -> ReMutable s m a -> n () Source # modifyRef :: Ref n (ReMutable s m a) -> (ReMutable s m a -> ReMutable s m a) -> n () Source # modifyRef' :: Ref n (ReMutable s m a) -> (ReMutable s m a -> ReMutable s m a) -> n () Source # updateRef :: Ref n (ReMutable s m a) -> (ReMutable s m a -> (ReMutable s m a, b)) -> n b Source # updateRef' :: Ref n (ReMutable s m a) -> (ReMutable s m a -> (ReMutable s m a, b)) -> n b Source # | |
(Monad m, Mutable m a, Mutable m b, Mutable m c, Mutable m d) => Mutable m (a, b, c, d) Source # | |
Defined in Numeric.Opto.Ref thawRef :: (a, b, c, d) -> m (Ref m (a, b, c, d)) Source # freezeRef :: Ref m (a, b, c, d) -> m (a, b, c, d) Source # copyRef :: Ref m (a, b, c, d) -> (a, b, c, d) -> m () Source # modifyRef :: Ref m (a, b, c, d) -> ((a, b, c, d) -> (a, b, c, d)) -> m () Source # modifyRef' :: Ref m (a, b, c, d) -> ((a, b, c, d) -> (a, b, c, d)) -> m () Source # updateRef :: Ref m (a, b, c, d) -> ((a, b, c, d) -> ((a, b, c, d), b0)) -> m b0 Source # updateRef' :: Ref m (a, b, c, d) -> ((a, b, c, d) -> ((a, b, c, d), b0)) -> m b0 Source # |
Newtype wrapper that can provide any type with a Mutable
instance.
Can be useful for avoiding orphan instances.
Instances
PrimMonad m => Mutable m (MutRef a) Source # | |
Defined in Numeric.Opto.Ref thawRef :: MutRef a -> m (Ref m (MutRef a)) Source # freezeRef :: Ref m (MutRef a) -> m (MutRef a) Source # copyRef :: Ref m (MutRef a) -> MutRef a -> m () Source # modifyRef :: Ref m (MutRef a) -> (MutRef a -> MutRef a) -> m () Source # modifyRef' :: Ref m (MutRef a) -> (MutRef a -> MutRef a) -> m () Source # updateRef :: Ref m (MutRef a) -> (MutRef a -> (MutRef a, b)) -> m b Source # updateRef' :: Ref m (MutRef a) -> (MutRef a -> (MutRef a, b)) -> m b Source # | |
IsoHKD MutRef (a :: Type) Source # | |
type Ref m (MutRef a) Source # | |
type HKD MutRef (a :: Type) Source # | |
Defined in Numeric.Opto.Ref |
Instances
class Monad m => GMutable m f Source #
gThawRef_, gFreezeRef_, gCopyRef_
ReMutable
reMutable :: forall m n a r. (Mutable m a, Monad n) => (forall x. m x -> n x) -> (Mutable n a => r) -> r Source #
reMutableConstraint :: forall m n a. (Mutable m a, Monad n) => (forall x. m x -> n x) -> Mutable m a :- Mutable n a Source #
newtype ReMutable (s :: Type) m a Source #
Instances
(Monad n, Mutable m a, Reifies s (ReMutableTrans m n)) => Mutable n (ReMutable s m a) Source # | |
Defined in Numeric.Opto.Ref thawRef :: ReMutable s m a -> n (Ref n (ReMutable s m a)) Source # freezeRef :: Ref n (ReMutable s m a) -> n (ReMutable s m a) Source # copyRef :: Ref n (ReMutable s m a) -> ReMutable s m a -> n () Source # modifyRef :: Ref n (ReMutable s m a) -> (ReMutable s m a -> ReMutable s m a) -> n () Source # modifyRef' :: Ref n (ReMutable s m a) -> (ReMutable s m a -> ReMutable s m a) -> n () Source # updateRef :: Ref n (ReMutable s m a) -> (ReMutable s m a -> (ReMutable s m a, b)) -> n b Source # updateRef' :: Ref n (ReMutable s m a) -> (ReMutable s m a -> (ReMutable s m a, b)) -> n b Source # | |
type Ref n (ReMutable s m a) Source # | |
Defined in Numeric.Opto.Ref |
newtype ReMutableTrans m n Source #