{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Data.Mutable.Parts (
MutPart(..)
, withPart
, freezePart, copyPart
, movePartInto, movePartOver, movePartWithin
, clonePart, unsafeFreezePart
, modifyPart, modifyPart'
, updatePart, updatePart'
, modifyPartM, modifyPartM'
, updatePartM, updatePartM'
, compMP
, idMP
, mutFst, mutSnd
, FieldMut(..), withField, mutField, Label(..)
, PosMut(..), withPos, mutPos
, TupleMut(..), withTuple
, hkdMutParts, HKDMutParts
, mutRec
, coerceRef, withCoerceRef
, MapRef
) where
import Data.Coerce
import Data.Generics.Product.Internal.HList
import Data.Kind
import Data.Mutable.Class
import Data.Mutable.Instances
import Data.Vinyl hiding (HList)
import Data.Vinyl.Functor
import GHC.Generics
import GHC.TypeLits
import qualified Control.Category as C
import qualified Data.GenericLens.Internal as GL
import qualified Data.Generics.Internal.Profunctor.Lens as GLP
import qualified Data.Generics.Product.Fields as GL
import qualified Data.Generics.Product.Internal.GLens as GL
import qualified Data.Generics.Product.Internal.Positions as GL
import qualified Data.Generics.Product.Positions as GL
import qualified Data.Vinyl.TypeLevel as V
import qualified Data.Vinyl.XRec as X
newtype MutPart m s a = MutPart { MutPart m s a -> Ref m s -> Ref m a
getMutPart :: Ref m s -> Ref m a }
compMP :: MutPart m a b -> MutPart m b c -> MutPart m a c
compMP :: MutPart m a b -> MutPart m b c -> MutPart m a c
compMP (MutPart f :: Ref m a -> Ref m b
f) (MutPart g :: Ref m b -> Ref m c
g) = (Ref m a -> Ref m c) -> MutPart m a c
forall (m :: * -> *) s a. (Ref m s -> Ref m a) -> MutPart m s a
MutPart (Ref m b -> Ref m c
g (Ref m b -> Ref m c) -> (Ref m a -> Ref m b) -> Ref m a -> Ref m c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ref m a -> Ref m b
f)
infixr 9 `compMP`
idMP :: MutPart m a a
idMP :: MutPart m a a
idMP = (Ref m a -> Ref m a) -> MutPart m a a
forall (m :: * -> *) s a. (Ref m s -> Ref m a) -> MutPart m s a
MutPart Ref m a -> Ref m a
forall a. a -> a
id
instance C.Category (MutPart m) where
id :: MutPart m a a
id = MutPart m a a
forall (m :: * -> *) a. MutPart m a a
idMP
. :: MutPart m b c -> MutPart m a b -> MutPart m a c
(.) = (MutPart m a b -> MutPart m b c -> MutPart m a c)
-> MutPart m b c -> MutPart m a b -> MutPart m a c
forall a b c. (a -> b -> c) -> b -> a -> c
flip MutPart m a b -> MutPart m b c -> MutPart m a c
forall (m :: * -> *) a b c.
MutPart m a b -> MutPart m b c -> MutPart m a c
compMP
instance X.IsoHKD (MutPart m s) a
mutFst :: MutPart m (a, b) a
mutFst :: MutPart m (a, b) a
mutFst = (Ref m (a, b) -> Ref m a) -> MutPart m (a, b) a
forall (m :: * -> *) s a. (Ref m s -> Ref m a) -> MutPart m s a
MutPart Ref m (a, b) -> Ref m a
forall a b. (a, b) -> a
fst
mutSnd :: MutPart m (a, b) b
mutSnd :: MutPart m (a, b) b
mutSnd = (Ref m (a, b) -> Ref m b) -> MutPart m (a, b) b
forall (m :: * -> *) s a. (Ref m s -> Ref m a) -> MutPart m s a
MutPart Ref m (a, b) -> Ref m b
forall a b. (a, b) -> b
snd
withPart
:: MutPart m s a
-> Ref m s
-> (Ref m a -> m r)
-> m r
withPart :: MutPart m s a -> Ref m s -> (Ref m a -> m r) -> m r
withPart mp :: MutPart m s a
mp x :: Ref m s
x f :: Ref m a -> m r
f = Ref m a -> m r
f (MutPart m s a -> Ref m s -> Ref m a
forall (m :: * -> *) s a. MutPart m s a -> Ref m s -> Ref m a
getMutPart MutPart m s a
mp Ref m s
x)
freezePart :: Mutable m a => MutPart m s a -> Ref m s -> m a
freezePart :: MutPart m s a -> Ref m s -> m a
freezePart mp :: MutPart m s a
mp = Ref m a -> m a
forall (m :: * -> *) a. Mutable m a => Ref m a -> m a
freezeRef (Ref m a -> m a) -> (Ref m s -> Ref m a) -> Ref m s -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutPart m s a -> Ref m s -> Ref m a
forall (m :: * -> *) s a. MutPart m s a -> Ref m s -> Ref m a
getMutPart MutPart m s a
mp
copyPart :: Mutable m a => MutPart m s a -> Ref m s -> a -> m ()
copyPart :: MutPart m s a -> Ref m s -> a -> m ()
copyPart mp :: MutPart m s a
mp = Ref m a -> a -> m ()
forall (m :: * -> *) a. Mutable m a => Ref m a -> a -> m ()
copyRef (Ref m a -> a -> m ())
-> (Ref m s -> Ref m a) -> Ref m s -> a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutPart m s a -> Ref m s -> Ref m a
forall (m :: * -> *) s a. MutPart m s a -> Ref m s -> Ref m a
getMutPart MutPart m s a
mp
movePartInto
:: Mutable m a
=> MutPart m s a
-> Ref m s
-> Ref m a
-> m ()
movePartInto :: MutPart m s a -> Ref m s -> Ref m a -> m ()
movePartInto mp :: MutPart m s a
mp = Ref m a -> Ref m a -> m ()
forall (m :: * -> *) a. Mutable m a => Ref m a -> Ref m a -> m ()
moveRef (Ref m a -> Ref m a -> m ())
-> (Ref m s -> Ref m a) -> Ref m s -> Ref m a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutPart m s a -> Ref m s -> Ref m a
forall (m :: * -> *) s a. MutPart m s a -> Ref m s -> Ref m a
getMutPart MutPart m s a
mp
movePartOver
:: Mutable m a
=> MutPart m s a
-> Ref m a
-> Ref m s
-> m ()
movePartOver :: MutPart m s a -> Ref m a -> Ref m s -> m ()
movePartOver mp :: MutPart m s a
mp r :: Ref m a
r = Ref m a -> Ref m a -> m ()
forall (m :: * -> *) a. Mutable m a => Ref m a -> Ref m a -> m ()
moveRef Ref m a
r (Ref m a -> m ()) -> (Ref m s -> Ref m a) -> Ref m s -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutPart m s a -> Ref m s -> Ref m a
forall (m :: * -> *) s a. MutPart m s a -> Ref m s -> Ref m a
getMutPart MutPart m s a
mp
movePartWithin
:: Mutable m a
=> MutPart m s a
-> Ref m s
-> Ref m s
-> m ()
movePartWithin :: MutPart m s a -> Ref m s -> Ref m s -> m ()
movePartWithin mp :: MutPart m s a
mp r :: Ref m s
r v :: Ref m s
v = Ref m a -> Ref m a -> m ()
forall (m :: * -> *) a. Mutable m a => Ref m a -> Ref m a -> m ()
moveRef (MutPart m s a -> Ref m s -> Ref m a
forall (m :: * -> *) s a. MutPart m s a -> Ref m s -> Ref m a
getMutPart MutPart m s a
mp Ref m s
r) (MutPart m s a -> Ref m s -> Ref m a
forall (m :: * -> *) s a. MutPart m s a -> Ref m s -> Ref m a
getMutPart MutPart m s a
mp Ref m s
v)
clonePart
:: Mutable m a
=> MutPart m s a
-> Ref m s
-> m (Ref m a)
clonePart :: MutPart m s a -> Ref m s -> m (Ref m a)
clonePart mp :: MutPart m s a
mp = Ref m a -> m (Ref m a)
forall (m :: * -> *) a. Mutable m a => Ref m a -> m (Ref m a)
cloneRef (Ref m a -> m (Ref m a))
-> (Ref m s -> Ref m a) -> Ref m s -> m (Ref m a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutPart m s a -> Ref m s -> Ref m a
forall (m :: * -> *) s a. MutPart m s a -> Ref m s -> Ref m a
getMutPart MutPart m s a
mp
unsafeFreezePart :: Mutable m a => MutPart m s a -> Ref m s -> m a
unsafeFreezePart :: MutPart m s a -> Ref m s -> m a
unsafeFreezePart mp :: MutPart m s a
mp = Ref m a -> m a
forall (m :: * -> *) a. Mutable m a => Ref m a -> m a
unsafeFreezeRef (Ref m a -> m a) -> (Ref m s -> Ref m a) -> Ref m s -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutPart m s a -> Ref m s -> Ref m a
forall (m :: * -> *) s a. MutPart m s a -> Ref m s -> Ref m a
getMutPart MutPart m s a
mp
modifyPart :: Mutable m a => MutPart m s a -> Ref m s -> (a -> a) -> m ()
modifyPart :: MutPart m s a -> Ref m s -> (a -> a) -> m ()
modifyPart mp :: MutPart m s a
mp = Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. Mutable m a => Ref m a -> (a -> a) -> m ()
modifyRef (Ref m a -> (a -> a) -> m ())
-> (Ref m s -> Ref m a) -> Ref m s -> (a -> a) -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutPart m s a -> Ref m s -> Ref m a
forall (m :: * -> *) s a. MutPart m s a -> Ref m s -> Ref m a
getMutPart MutPart m s a
mp
modifyPart' :: Mutable m a => MutPart m s a -> Ref m s -> (a -> a) -> m ()
modifyPart' :: MutPart m s a -> Ref m s -> (a -> a) -> m ()
modifyPart' mp :: MutPart m s a
mp = Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. Mutable m a => Ref m a -> (a -> a) -> m ()
modifyRef' (Ref m a -> (a -> a) -> m ())
-> (Ref m s -> Ref m a) -> Ref m s -> (a -> a) -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutPart m s a -> Ref m s -> Ref m a
forall (m :: * -> *) s a. MutPart m s a -> Ref m s -> Ref m a
getMutPart MutPart m s a
mp
updatePart :: Mutable m a => MutPart m s a -> Ref m s -> (a -> (a, b)) -> m b
updatePart :: MutPart m s a -> Ref m s -> (a -> (a, b)) -> m b
updatePart mp :: MutPart m s a
mp = Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
Mutable m a =>
Ref m a -> (a -> (a, b)) -> m b
updateRef (Ref m a -> (a -> (a, b)) -> m b)
-> (Ref m s -> Ref m a) -> Ref m s -> (a -> (a, b)) -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutPart m s a -> Ref m s -> Ref m a
forall (m :: * -> *) s a. MutPart m s a -> Ref m s -> Ref m a
getMutPart MutPart m s a
mp
updatePart' :: Mutable m a => MutPart m s a -> Ref m s -> (a -> (a, b)) -> m b
updatePart' :: MutPart m s a -> Ref m s -> (a -> (a, b)) -> m b
updatePart' mp :: MutPart m s a
mp = Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
Mutable m a =>
Ref m a -> (a -> (a, b)) -> m b
updateRef' (Ref m a -> (a -> (a, b)) -> m b)
-> (Ref m s -> Ref m a) -> Ref m s -> (a -> (a, b)) -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutPart m s a -> Ref m s -> Ref m a
forall (m :: * -> *) s a. MutPart m s a -> Ref m s -> Ref m a
getMutPart MutPart m s a
mp
modifyPartM :: Mutable m a => MutPart m s a -> Ref m s -> (a -> m a) -> m ()
modifyPartM :: MutPart m s a -> Ref m s -> (a -> m a) -> m ()
modifyPartM mp :: MutPart m s a
mp = Ref m a -> (a -> m a) -> m ()
forall (m :: * -> *) a.
Mutable m a =>
Ref m a -> (a -> m a) -> m ()
modifyRefM (Ref m a -> (a -> m a) -> m ())
-> (Ref m s -> Ref m a) -> Ref m s -> (a -> m a) -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutPart m s a -> Ref m s -> Ref m a
forall (m :: * -> *) s a. MutPart m s a -> Ref m s -> Ref m a
getMutPart MutPart m s a
mp
modifyPartM' :: Mutable m a => MutPart m s a -> Ref m s -> (a -> m a) -> m ()
modifyPartM' :: MutPart m s a -> Ref m s -> (a -> m a) -> m ()
modifyPartM' mp :: MutPart m s a
mp = Ref m a -> (a -> m a) -> m ()
forall (m :: * -> *) a.
Mutable m a =>
Ref m a -> (a -> m a) -> m ()
modifyRefM' (Ref m a -> (a -> m a) -> m ())
-> (Ref m s -> Ref m a) -> Ref m s -> (a -> m a) -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutPart m s a -> Ref m s -> Ref m a
forall (m :: * -> *) s a. MutPart m s a -> Ref m s -> Ref m a
getMutPart MutPart m s a
mp
updatePartM :: Mutable m a => MutPart m s a -> Ref m s -> (a -> m (a, b)) -> m b
updatePartM :: MutPart m s a -> Ref m s -> (a -> m (a, b)) -> m b
updatePartM mp :: MutPart m s a
mp = Ref m a -> (a -> m (a, b)) -> m b
forall (m :: * -> *) a b.
Mutable m a =>
Ref m a -> (a -> m (a, b)) -> m b
updateRefM (Ref m a -> (a -> m (a, b)) -> m b)
-> (Ref m s -> Ref m a) -> Ref m s -> (a -> m (a, b)) -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutPart m s a -> Ref m s -> Ref m a
forall (m :: * -> *) s a. MutPart m s a -> Ref m s -> Ref m a
getMutPart MutPart m s a
mp
updatePartM' :: Mutable m a => MutPart m s a -> Ref m s -> (a -> m (a, b)) -> m b
updatePartM' :: MutPart m s a -> Ref m s -> (a -> m (a, b)) -> m b
updatePartM' mp :: MutPart m s a
mp = Ref m a -> (a -> m (a, b)) -> m b
forall (m :: * -> *) a b.
Mutable m a =>
Ref m a -> (a -> m (a, b)) -> m b
updateRefM' (Ref m a -> (a -> m (a, b)) -> m b)
-> (Ref m s -> Ref m a) -> Ref m s -> (a -> m (a, b)) -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MutPart m s a -> Ref m s -> Ref m a
forall (m :: * -> *) s a. MutPart m s a -> Ref m s -> Ref m a
getMutPart MutPart m s a
mp
mutRec
:: forall a as f rec m.
( Ref m (rec f as) ~ rec (RecRef m f) as
, RecElem rec a a as as (V.RIndex a as)
, RecElemFCtx rec (RecRef m f)
)
=> MutPart m (rec f as) (f a)
mutRec :: MutPart m (rec f as) (f a)
mutRec = (Ref m (rec f as) -> Ref m (f a)) -> MutPart m (rec f as) (f a)
forall (m :: * -> *) s a. (Ref m s -> Ref m a) -> MutPart m s a
MutPart ((Ref m (rec f as) -> Ref m (f a)) -> MutPart m (rec f as) (f a))
-> (Ref m (rec f as) -> Ref m (f a)) -> MutPart m (rec f as) (f a)
forall a b. (a -> b) -> a -> b
$ RecRef m f a -> Ref m (f a)
forall (m :: * -> *) k (f :: k -> *) (a :: k).
RecRef m f a -> Ref m (f a)
getRecRef (RecRef m f a -> Ref m (f a))
-> (rec (RecRef m f) as -> RecRef m f a)
-> rec (RecRef m f) as
-> Ref m (f a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RecElem rec a a as as (RIndex a as),
RecElemFCtx rec (RecRef m f)) =>
rec (RecRef m f) as -> RecRef m f a
forall k (r :: k) (rs :: [k]) (f :: k -> *)
(record :: (k -> *) -> [k] -> *).
(RecElem record r r rs rs (RIndex r rs), RecElemFCtx record f) =>
record f rs -> f r
rget @a @as @(RecRef m f) @rec
coerceRef :: (Ref m s ~ CoerceRef m s a) => MutPart m s a
coerceRef :: MutPart m s a
coerceRef = (Ref m s -> Ref m a) -> MutPart m s a
forall (m :: * -> *) s a. (Ref m s -> Ref m a) -> MutPart m s a
MutPart Ref m s -> Ref m a
forall a b. Coercible a b => a -> b
coerce
withCoerceRef
:: CoerceRef m s a
-> (Ref m a -> m r)
-> m r
withCoerceRef :: CoerceRef m s a -> (Ref m a -> m r) -> m r
withCoerceRef x :: CoerceRef m s a
x f :: Ref m a -> m r
f = Ref m a -> m r
f (CoerceRef m s a -> Ref m a
forall a b. Coercible a b => a -> b
coerce CoerceRef m s a
x)
class (Mutable m (z Identity), Ref m (z Identity) ~ z (RefFor m)) => HKDMutParts m z i o where
hkdMutParts_ :: (z (RefFor m) -> i a) -> o a
instance (Mutable m (z Identity), Ref m (z Identity) ~ z (RefFor m)) => HKDMutParts m z (K1 i (RefFor m c)) (K1 i (MutPart m (z Identity) c)) where
hkdMutParts_ :: (z (RefFor m) -> K1 i (RefFor m c) a)
-> K1 i (MutPart m (z Identity) c) a
hkdMutParts_ f :: z (RefFor m) -> K1 i (RefFor m c) a
f = MutPart m (z Identity) c -> K1 i (MutPart m (z Identity) c) a
forall k i c (p :: k). c -> K1 i c p
K1 (MutPart m (z Identity) c -> K1 i (MutPart m (z Identity) c) a)
-> MutPart m (z Identity) c -> K1 i (MutPart m (z Identity) c) a
forall a b. (a -> b) -> a -> b
$ (Ref m (z Identity) -> Ref m c) -> MutPart m (z Identity) c
forall (m :: * -> *) s a. (Ref m s -> Ref m a) -> MutPart m s a
MutPart ((Ref m (z Identity) -> Ref m c) -> MutPart m (z Identity) c)
-> (Ref m (z Identity) -> Ref m c) -> MutPart m (z Identity) c
forall a b. (a -> b) -> a -> b
$ RefFor m c -> Ref m c
forall (m :: * -> *) a. RefFor m a -> Ref m a
getRefFor (RefFor m c -> Ref m c)
-> (z (RefFor m) -> RefFor m c) -> z (RefFor m) -> Ref m c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. K1 i (RefFor m c) a -> RefFor m c
forall i c k (p :: k). K1 i c p -> c
unK1 (K1 i (RefFor m c) a -> RefFor m c)
-> (z (RefFor m) -> K1 i (RefFor m c) a)
-> z (RefFor m)
-> RefFor m c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. z (RefFor m) -> K1 i (RefFor m c) a
f
instance (Mutable m (z Identity), Ref m (z Identity) ~ z (RefFor m)) => HKDMutParts m z U1 U1 where
hkdMutParts_ :: (z (RefFor m) -> U1 a) -> U1 a
hkdMutParts_ _ = U1 a
forall k (p :: k). U1 p
U1
instance (Mutable m (z Identity), Ref m (z Identity) ~ z (RefFor m), TypeError ('Text "Cannot use hkdMutParts for uninhabited types: " ':<>: 'ShowType z)) => HKDMutParts m z V1 V1 where
hkdMutParts_ :: (z (RefFor m) -> V1 a) -> V1 a
hkdMutParts_ _ = V1 a
forall a. HasCallStack => a
undefined
instance HKDMutParts m z i o => HKDMutParts m z (M1 a b i) (M1 a b o) where
hkdMutParts_ :: (z (RefFor m) -> M1 a b i a) -> M1 a b o a
hkdMutParts_ f :: z (RefFor m) -> M1 a b i a
f = o a -> M1 a b o a
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (o a -> M1 a b o a) -> o a -> M1 a b o a
forall a b. (a -> b) -> a -> b
$ (z (RefFor m) -> i a) -> o a
forall k (m :: * -> *) (z :: (* -> *) -> *) (i :: k -> *)
(o :: k -> *) (a :: k).
HKDMutParts m z i o =>
(z (RefFor m) -> i a) -> o a
hkdMutParts_ @m (M1 a b i a -> i a
forall i (c :: Meta) k (f :: k -> *) (p :: k). M1 i c f p -> f p
unM1 (M1 a b i a -> i a)
-> (z (RefFor m) -> M1 a b i a) -> z (RefFor m) -> i a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. z (RefFor m) -> M1 a b i a
f)
instance (HKDMutParts m z i o, HKDMutParts m z i' o') => HKDMutParts m z (i :*: i') (o :*: o') where
hkdMutParts_ :: (z (RefFor m) -> (:*:) i i' a) -> (:*:) o o' a
hkdMutParts_ f :: z (RefFor m) -> (:*:) i i' a
f = (z (RefFor m) -> i a) -> o a
forall k (m :: * -> *) (z :: (* -> *) -> *) (i :: k -> *)
(o :: k -> *) (a :: k).
HKDMutParts m z i o =>
(z (RefFor m) -> i a) -> o a
hkdMutParts_ @m ((\(x :: i a
x:*:_)->i a
x) ((:*:) i i' a -> i a)
-> (z (RefFor m) -> (:*:) i i' a) -> z (RefFor m) -> i a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. z (RefFor m) -> (:*:) i i' a
f) o a -> o' a -> (:*:) o o' a
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: (z (RefFor m) -> i' a) -> o' a
forall k (m :: * -> *) (z :: (* -> *) -> *) (i :: k -> *)
(o :: k -> *) (a :: k).
HKDMutParts m z i o =>
(z (RefFor m) -> i a) -> o a
hkdMutParts_ @m ((\(_:*:y :: i' a
y)->i' a
y) ((:*:) i i' a -> i' a)
-> (z (RefFor m) -> (:*:) i i' a) -> z (RefFor m) -> i' a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. z (RefFor m) -> (:*:) i i' a
f)
instance (Mutable m (z Identity), Ref m (z Identity) ~ z (RefFor m), TypeError ('Text "Cannot use hkdMutParts for sum types: " ':<>: 'ShowType z)) => HKDMutParts m z (i :+: i') o where
hkdMutParts_ :: (z (RefFor m) -> (:+:) i i' a) -> o a
hkdMutParts_ _ = o a
forall a. HasCallStack => a
undefined
hkdMutParts
:: forall z m.
( Generic (z (RefFor m))
, Generic (z (MutPart m (z Identity)))
, HKDMutParts m z (Rep (z (RefFor m))) (Rep (z (MutPart m (z Identity))))
)
=> z (MutPart m (z Identity))
hkdMutParts :: z (MutPart m (z Identity))
hkdMutParts = Rep (z (MutPart m (z Identity))) Any -> z (MutPart m (z Identity))
forall a x. Generic a => Rep a x -> a
to (Rep (z (MutPart m (z Identity))) Any
-> z (MutPart m (z Identity)))
-> Rep (z (MutPart m (z Identity))) Any
-> z (MutPart m (z Identity))
forall a b. (a -> b) -> a -> b
$ (z (RefFor m) -> Rep (z (RefFor m)) Any)
-> Rep (z (MutPart m (z Identity))) Any
forall k (m :: * -> *) (z :: (* -> *) -> *) (i :: k -> *)
(o :: k -> *) (a :: k).
HKDMutParts m z i o =>
(z (RefFor m) -> i a) -> o a
hkdMutParts_ @m @z z (RefFor m) -> Rep (z (RefFor m)) Any
forall a x. Generic a => a -> Rep a x
from
class (Mutable m s, Mutable m a) => FieldMut (fld :: Symbol) m s a | fld s -> a where
fieldMut
:: Label fld
-> MutPart m s a
instance
( Mutable m s
, Mutable m a
, Ref m s ~ GRef m s
, GL.GLens' (HasTotalFieldPSym fld) (GRef_ m (Rep s)) (Ref m a)
, GL.HasField' fld s a
)
=> FieldMut fld m s a where
fieldMut :: Label fld -> MutPart m s a
fieldMut _ = (Ref m s -> Ref m a) -> MutPart m s a
forall (m :: * -> *) s a. (Ref m s -> Ref m a) -> MutPart m s a
MutPart ((Ref m s -> Ref m a) -> MutPart m s a)
-> (Ref m s -> Ref m a) -> MutPart m s a
forall a b. (a -> b) -> a -> b
$ Lens (GRef_ m (Rep s) ()) (GRef_ m (Rep s) ()) (Ref m a) (Ref m a)
-> GRef_ m (Rep s) () -> Ref m a
forall s a. Lens s s a a -> s -> a
GLP.view (forall (s :: * -> *) (t :: * -> *) a b x.
GLens (HasTotalFieldPSym fld) s t a b =>
Lens (s x) (t x) a b
forall (pred :: Pred) (s :: * -> *) (t :: * -> *) a b x.
GLens pred s t a b =>
Lens (s x) (t x) a b
GL.glens @(HasTotalFieldPSym fld)) (GRef_ m (Rep s) () -> Ref m a)
-> (GRef m s -> GRef_ m (Rep s) ()) -> GRef m s -> Ref m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GRef m s -> GRef_ m (Rep s) ()
forall (m :: * -> *) a. GRef m a -> GRef_ m (Rep a) ()
unGRef
data HasTotalFieldPSym :: Symbol -> GL.TyFun (Type -> Type) (Maybe Type)
type instance GL.Eval (HasTotalFieldPSym sym) tt = GL.HasTotalFieldP sym tt
withField
:: FieldMut fld m s a
=> Label fld
-> Ref m s
-> (Ref m a -> m b)
-> m b
withField :: Label fld -> Ref m s -> (Ref m a -> m b) -> m b
withField l :: Label fld
l = MutPart m s a -> Ref m s -> (Ref m a -> m b) -> m b
forall (m :: * -> *) s a r.
MutPart m s a -> Ref m s -> (Ref m a -> m r) -> m r
withPart (Label fld -> MutPart m s a
forall (fld :: Symbol) (m :: * -> *) s a.
FieldMut fld m s a =>
Label fld -> MutPart m s a
fieldMut Label fld
l)
mutField
:: forall fld m s a. FieldMut fld m s a
=> Label fld
-> Ref m s
-> Ref m a
mutField :: Label fld -> Ref m s -> Ref m a
mutField = MutPart m s a -> Ref m s -> Ref m a
forall (m :: * -> *) s a. MutPart m s a -> Ref m s -> Ref m a
getMutPart (MutPart m s a -> Ref m s -> Ref m a)
-> (Label fld -> MutPart m s a) -> Label fld -> Ref m s -> Ref m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. FieldMut fld m s a => Label fld -> MutPart m s a
forall (fld :: Symbol) (m :: * -> *) s a.
FieldMut fld m s a =>
Label fld -> MutPart m s a
fieldMut @_ @m
class (Mutable m s, Mutable m a) => PosMut (i :: Nat) m s a | i s -> a where
posMut :: MutPart m s a
instance
( Mutable m s
, Mutable m a
, Ref m s ~ GRef m s
, gref ~ Fst (Traverse (GRef_ m (GL.CRep s)) 1)
, Coercible (GRef_ m (Rep s) ()) (gref ())
, GL.GLens' (HasTotalPositionPSym i) gref (Ref m a)
, GL.HasPosition' i s a
)
=> PosMut i m s a where
posMut :: MutPart m s a
posMut = (Ref m s -> Ref m a) -> MutPart m s a
forall (m :: * -> *) s a. (Ref m s -> Ref m a) -> MutPart m s a
MutPart ((Ref m s -> Ref m a) -> MutPart m s a)
-> (Ref m s -> Ref m a) -> MutPart m s a
forall a b. (a -> b) -> a -> b
$ Lens (gref ()) (gref ()) (Ref m a) (Ref m a) -> gref () -> Ref m a
forall s a. Lens s s a a -> s -> a
GLP.view (forall (t :: * -> *) a b x.
GLens (HasTotalPositionPSym i) gref t a b =>
Lens (gref x) (t x) a b
forall (pred :: Pred) (s :: * -> *) (t :: * -> *) a b x.
GLens pred s t a b =>
Lens (s x) (t x) a b
GL.glens @(HasTotalPositionPSym i) @gref) (gref () -> Ref m a)
-> (GRef m s -> gref ()) -> GRef m s -> Ref m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Coercible (GRef_ m (Rep s) ()) (gref ()) =>
GRef_ m (Rep s) () -> gref ()
forall a b. Coercible a b => a -> b
coerce @_ @(gref ()) (GRef_ m (Rep s) () -> gref ())
-> (GRef m s -> GRef_ m (Rep s) ()) -> GRef m s -> gref ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GRef m s -> GRef_ m (Rep s) ()
forall (m :: * -> *) a. GRef m a -> GRef_ m (Rep a) ()
unGRef
data HasTotalPositionPSym :: Nat -> GL.TyFun (Type -> Type) (Maybe Type)
type instance GL.Eval (HasTotalPositionPSym t) tt = GL.HasTotalPositionP t tt
withPos
:: forall i m s a r. PosMut i m s a
=> Ref m s
-> (Ref m a -> m r)
-> m r
withPos :: Ref m s -> (Ref m a -> m r) -> m r
withPos = MutPart m s a -> Ref m s -> (Ref m a -> m r) -> m r
forall (m :: * -> *) s a r.
MutPart m s a -> Ref m s -> (Ref m a -> m r) -> m r
withPart (forall (i :: Nat) (m :: * -> *) s a.
PosMut i m s a =>
MutPart m s a
forall (m :: * -> *) s a. PosMut i m s a => MutPart m s a
posMut @i)
mutPos
:: forall i m s a. PosMut i m s a
=> Ref m s
-> Ref m a
mutPos :: Ref m s -> Ref m a
mutPos = MutPart m s a -> Ref m s -> Ref m a
forall (m :: * -> *) s a. MutPart m s a -> Ref m s -> Ref m a
getMutPart (forall s a. PosMut i m s a => MutPart m s a
forall (i :: Nat) (m :: * -> *) s a.
PosMut i m s a =>
MutPart m s a
posMut @i @m)
class (Mutable m s, Mutable m a) => TupleMut m s a | s -> a where
tupleMut :: MutPart m s a
instance
( Mutable m s
, Mutable m a
, Ref m s ~ GRef m s
, GIsList (GRef_ m (Rep s)) (GRef_ m (Rep s)) (MapRef m as) (MapRef m as)
, GIsList (Rep s) (Rep s) as as
, ListTuple a a as as
, ListTuple b b (MapRef m as) (MapRef m as)
, Ref m a ~ b
)
=> TupleMut m s a where
tupleMut :: MutPart m s a
tupleMut = (Ref m s -> Ref m a) -> MutPart m s a
forall (m :: * -> *) s a. (Ref m s -> Ref m a) -> MutPart m s a
MutPart ((Ref m s -> Ref m a) -> MutPart m s a)
-> (Ref m s -> Ref m a) -> MutPart m s a
forall a b. (a -> b) -> a -> b
$ ListTuple b b (MapRef m as) (MapRef m as) =>
HList (MapRef m as) -> b
forall tuple tuple' (as :: [*]) (bs :: [*]).
ListTuple tuple tuple' as bs =>
HList as -> tuple
listToTuple @b @b @(MapRef m as) @(MapRef m as)
(HList (MapRef m as) -> b)
-> (GRef m s -> HList (MapRef m as)) -> GRef m s -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lens
(GRef_ m (Rep s) ())
(GRef_ m (Rep s) ())
(HList (MapRef m as))
(HList (MapRef m as))
-> GRef_ m (Rep s) () -> HList (MapRef m as)
forall s a. Lens s s a a -> s -> a
GLP.view forall (f :: * -> *) (g :: * -> *) (as :: [*]) (bs :: [*]) x.
GIsList f g as bs =>
Iso (f x) (g x) (HList as) (HList bs)
Lens
(GRef_ m (Rep s) ())
(GRef_ m (Rep s) ())
(HList (MapRef m as))
(HList (MapRef m as))
glist
(GRef_ m (Rep s) () -> HList (MapRef m as))
-> (GRef m s -> GRef_ m (Rep s) ())
-> GRef m s
-> HList (MapRef m as)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GRef m s -> GRef_ m (Rep s) ()
forall (m :: * -> *) a. GRef m a -> GRef_ m (Rep a) ()
unGRef
withTuple
:: TupleMut m s a
=> Ref m s
-> (Ref m a -> m r)
-> m r
withTuple :: Ref m s -> (Ref m a -> m r) -> m r
withTuple = MutPart m s a -> Ref m s -> (Ref m a -> m r) -> m r
forall (m :: * -> *) s a r.
MutPart m s a -> Ref m s -> (Ref m a -> m r) -> m r
withPart MutPart m s a
forall (m :: * -> *) s a. TupleMut m s a => MutPart m s a
tupleMut
type G = Type -> Type
type family Traverse (a :: G) (n :: Nat) :: (G, Nat) where
Traverse (M1 mt m s) n
= Traverse1 (M1 mt m) (Traverse s n)
Traverse (l :+: r) n
= '(Fst (Traverse l n) :+: Fst (Traverse r n), n)
Traverse (l :*: r) n
= TraverseProd (:*:) (Traverse l n) r
Traverse (K1 _ p) n
= '(K1 (GL.Pos n) p, n + 1)
Traverse U1 n
= '(U1, n)
type family Traverse1 (w :: G -> G) (z :: (G, Nat)) :: (G, Nat) where
Traverse1 w '(i, n) = '(w i, n)
type family TraverseProd (c :: G -> G -> G) (a :: (G, Nat)) (r :: G) :: (G, Nat) where
TraverseProd w '(i, n) r = Traverse1 (w i) (Traverse r n)
type family Fst (p :: (a, b)) :: a where
Fst '(a, b) = a