{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE Trustworthy #-}
module Polytropos
(
type Record
, type RecordF
, type Variant
, type VariantF
, type Row
, type SumRow
, type ProductRow
#if __GLASGOW_HASKELL__ >= 914
, data Variant
, data VariantF
#else
, pattern Variant
, pattern VariantF
#endif
, emptyRecord
, emptyRecordF
, insertField
, insertFieldF
, injectVariant
, injectVariantF
, projectVariant
, projectVariantF
, type ConstructorPayload
, type ConstructorPayloadHKD
, SubRow(..)
, SubSum(..)
, projectRecord
, projectRecordF
, widenVariant
, widenVariantF
, narrowVariant
, narrowVariantF
, peel
, peelF
, type Delete
, type HandlerRecordRow
, type HandlerRecordRowM
, type HandlerRecordRowHetero
, type HandlerRecordRowHeteroM
, eliminateUniform
, eliminateUniformM
, eliminate
, eliminateM
, matchVariant
, Pair(..)
, HasField(..)
, RowEq(..)
, RowShow(..)
, RowFlavour(..)
, Field(..)
, AllFields(..)
, DictAllFields
, FieldNames
, SimpleFieldTypes
, FieldTypes
, KnownHash(..)
, labelHash
, hashVal
, fnv1a64
, REC(..)
, REC_F(..)
, VAR(..)
, type VARIANT
#if __GLASGOW_HASKELL__ >= 914
, data VARIANT
#else
, pattern VARIANT
#endif
, REC_UPD(..)
, REC_UPD_F(..)
, OpenRecord
, OpenVariant
, recordField
, setField
, setFieldF
, cmapRecord
, cfoldMapRecord
, czipWithRecord
, cmapRecordF
, cfoldMapRecordF
) where
import Polytropos.Core
import Data.Functor.Identity (Identity(..))
import Data.Kind (Type)
import Data.Primitive.SmallArray (indexSmallArray, sizeofSmallArray, thawSmallArray, writeSmallArray, runSmallArray)
import GHC.Exts (toList, Any)
import GHC.Records (HasField(..))
import GHC.TypeLits (Symbol)
import Unsafe.Coerce (unsafeCoerce)
type RecordF (f :: Type -> Type) (r :: ProductRow f) = RowRep f ProductRowHKDT r ()
type Record (r :: Row) = RowRep Identity ProductRowT r ()
type VariantF (f :: Type -> Type) (s :: SumRowHKD f) = RowRep f SumRowHKDT s ()
type Variant (s :: SumRow) = RowRep Identity SumRowT s ()
emptyRecordF :: RecordF f '[]
emptyRecordF :: forall (f :: * -> *). RecordF f '[]
emptyRecordF = Rep f () -> RowRep f 'ProductRowHKDT '[] ()
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep ([f Any] -> Rep f ()
forall {k} (f :: * -> *) (a :: k). [f Any] -> Rep f a
productRep [])
insertFieldF :: Field n -> f a -> RecordF f r -> RecordF f ((n ':= f a) ': r)
insertFieldF :: forall (n :: Symbol) (f :: * -> *) a (r :: ProductRow f).
Field n -> f a -> RecordF f r -> RecordF f ((n ':= f a) : r)
insertFieldF Field n
_ f a
fa (RowRep Rep f ()
r) =
Rep f () -> RowRep f 'ProductRowHKDT ((n ':= f a) : r) ()
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep ([f Any] -> Rep f ()
forall {k} (f :: * -> *) (a :: k). [f Any] -> Rep f a
productRep (f a -> f Any
forall a b. a -> b
unsafeCoerce f a
fa f Any -> [f Any] -> [f Any]
forall a. a -> [a] -> [a]
: SmallArray (f Any) -> [Item (SmallArray (f Any))]
forall l. IsList l => l -> [Item l]
toList (Rep f () -> SmallArray (f Any)
forall {k} (f :: * -> *) (a :: k). Rep f a -> SmallArray (f Any)
repVals Rep f ()
r)))
emptyRecord :: Record '[]
emptyRecord :: Record '[]
emptyRecord = Rep Identity () -> Record '[]
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep ([Identity Any] -> Rep Identity ()
forall {k} (f :: * -> *) (a :: k). [f Any] -> Rep f a
productRep [])
insertField :: Field n -> a -> Record r -> Record ((n ':= a) ': r)
insertField :: forall (n :: Symbol) a (r :: ProductRow f).
Field n -> a -> Record r -> Record ((n ':= a) : r)
insertField Field n
_ a
a (RowRep Rep Identity ()
r) =
Rep Identity () -> RowRep Identity 'ProductRowT ((n ':= a) : r) ()
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep ([Identity Any] -> Rep Identity ()
forall {k} (f :: * -> *) (a :: k). [f Any] -> Rep f a
productRep (Any -> Identity Any
forall a. a -> Identity a
Identity (a -> Any
forall a b. a -> b
unsafeCoerce a
a) Identity Any -> [Identity Any] -> [Identity Any]
forall a. a -> [a] -> [a]
: SmallArray (Identity Any) -> [Item (SmallArray (Identity Any))]
forall l. IsList l => l -> [Item l]
toList (Rep Identity () -> SmallArray (Identity Any)
forall {k} (f :: * -> *) (a :: k). Rep f a -> SmallArray (f Any)
repVals Rep Identity ()
r)))
type family ConstructorPayload (n :: Symbol) (s :: SumRow) :: Row where
ConstructorPayload n ((n ':= fs) ': rest) = fs
ConstructorPayload n ((m ':= fs) ': rest) = ConstructorPayload n rest
type family ConstructorPayloadHKD (f :: Type -> Type) (n :: Symbol) (s :: SumRowHKD f) :: ProductRow f where
ConstructorPayloadHKD f n ((n ':= fs) ': rest) = fs
ConstructorPayloadHKD f n ((m ':= fs) ': rest) = ConstructorPayloadHKD f n rest
injectVariantF :: forall (n :: Symbol) (f :: Type -> Type) (s :: SumRowHKD f) (fs :: ProductRow f).
ConstructorIndex n s => Field n -> RecordF f fs -> VariantF f s
injectVariantF :: forall (n :: Symbol) (f :: * -> *) (s :: SumRow)
(fs :: ProductRow f).
ConstructorIndex n s =>
Field n -> RecordF f fs -> VariantF f s
injectVariantF Field n
_ (RowRep Rep f ()
r) =
Rep f () -> RowRep f 'SumRowHKDT s ()
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep (Word -> [f Any] -> Rep f ()
forall {k} (f :: * -> *) (a :: k). Word -> [f Any] -> Rep f a
injectRep (forall {kn} k (n :: kn) (row :: k). ConstructorIndex n row => Word
forall k (n :: Symbol) (row :: k). ConstructorIndex n row => Word
constructorIndex @_ @n @s) (SmallArray (f Any) -> [Item (SmallArray (f Any))]
forall l. IsList l => l -> [Item l]
toList (Rep f () -> SmallArray (f Any)
forall {k} (f :: * -> *) (a :: k). Rep f a -> SmallArray (f Any)
repVals Rep f ()
r)))
projectVariantF :: forall (n :: Symbol) (f :: Type -> Type) (s :: SumRowHKD f).
ConstructorIndex n s
=> Field n -> VariantF f s -> Maybe (RecordF f (ConstructorPayloadHKD f n s))
projectVariantF :: forall (n :: Symbol) (f :: * -> *) (s :: SumRow).
ConstructorIndex n s =>
Field n
-> VariantF f s -> Maybe (RecordF f (ConstructorPayloadHKD f n s))
projectVariantF Field n
_ (RowRep Rep f ()
r) =
case Word -> Rep f () -> Maybe [f Any]
forall {k} (f :: * -> *) (a :: k). Word -> Rep f a -> Maybe [f Any]
projectRep (forall {kn} k (n :: kn) (row :: k). ConstructorIndex n row => Word
forall k (n :: Symbol) (row :: k). ConstructorIndex n row => Word
constructorIndex @_ @n @s) Rep f ()
r of
Just [f Any]
vals -> RecordF f (ConstructorPayloadHKD f n s)
-> Maybe (RecordF f (ConstructorPayloadHKD f n s))
forall a. a -> Maybe a
Just (Rep f () -> RecordF f (ConstructorPayloadHKD f n s)
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep ([f Any] -> Rep f ()
forall {k} (f :: * -> *) (a :: k). [f Any] -> Rep f a
productRep [f Any]
vals))
Maybe [f Any]
Nothing -> Maybe (RecordF f (ConstructorPayloadHKD f n s))
forall a. Maybe a
Nothing
pattern VariantF :: forall (n :: Symbol) (f :: Type -> Type) (s :: SumRowHKD f).
ConstructorIndex n s
=> Field n -> RecordF f (ConstructorPayloadHKD f n s) -> VariantF f s
pattern $bVariantF :: forall (n :: Symbol) (f :: * -> *) (s :: SumRow).
ConstructorIndex n s =>
Field n -> RecordF f (ConstructorPayloadHKD f n s) -> VariantF f s
$mVariantF :: forall {r} {n :: Symbol} {f :: * -> *} {s :: SumRow}.
ConstructorIndex n s =>
VariantF f s
-> (Field n -> RecordF f (ConstructorPayloadHKD f n s) -> r)
-> ((# #) -> r)
-> r
VariantF f r <- ( (\VariantF f s
v -> (Field n
forall (n :: Symbol). Field n
Field :: Field n, Field n
-> VariantF f s -> Maybe (RecordF f (ConstructorPayloadHKD f n s))
forall (n :: Symbol) (f :: * -> *) (s :: SumRow).
ConstructorIndex n s =>
Field n
-> VariantF f s -> Maybe (RecordF f (ConstructorPayloadHKD f n s))
projectVariantF (Field n
forall (n :: Symbol). Field n
Field :: Field n) VariantF f s
v)) -> (f, Just r) )
where VariantF Field n
f RecordF f (ConstructorPayloadHKD f n s)
r = Field n -> RecordF f (ConstructorPayloadHKD f n s) -> VariantF f s
forall (n :: Symbol) (f :: * -> *) (s :: SumRow)
(fs :: ProductRow f).
ConstructorIndex n s =>
Field n -> RecordF f fs -> VariantF f s
injectVariantF Field n
f RecordF f (ConstructorPayloadHKD f n s)
r
injectVariant :: forall n s fs. ConstructorIndex n s => Field n -> Record fs -> Variant s
injectVariant :: forall (n :: Symbol) (s :: SumRow) (fs :: ProductRow f).
ConstructorIndex n s =>
Field n -> Record fs -> Variant s
injectVariant Field n
_ (RowRep Rep Identity ()
r) =
Rep Identity () -> RowRep Identity 'SumRowT s ()
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep (Word -> [Identity Any] -> Rep Identity ()
forall {k} (f :: * -> *) (a :: k). Word -> [f Any] -> Rep f a
injectRep (forall {kn} k (n :: kn) (row :: k). ConstructorIndex n row => Word
forall k (n :: Symbol) (row :: k). ConstructorIndex n row => Word
constructorIndex @_ @n @s) (SmallArray (Identity Any) -> [Item (SmallArray (Identity Any))]
forall l. IsList l => l -> [Item l]
toList (Rep Identity () -> SmallArray (Identity Any)
forall {k} (f :: * -> *) (a :: k). Rep f a -> SmallArray (f Any)
repVals Rep Identity ()
r)))
projectVariant :: forall (n :: Symbol) (s :: SumRow).
ConstructorIndex n s
=> Field n -> Variant s -> Maybe (Record (ConstructorPayload n s))
projectVariant :: forall (n :: Symbol) (s :: SumRow).
ConstructorIndex n s =>
Field n -> Variant s -> Maybe (Record (ConstructorPayload n s))
projectVariant Field n
_ (RowRep Rep Identity ()
r) =
case Word -> Rep Identity () -> Maybe [Identity Any]
forall {k} (f :: * -> *) (a :: k). Word -> Rep f a -> Maybe [f Any]
projectRep (forall {kn} k (n :: kn) (row :: k). ConstructorIndex n row => Word
forall k (n :: Symbol) (row :: k). ConstructorIndex n row => Word
constructorIndex @_ @n @s) Rep Identity ()
r of
Just [Identity Any]
vals -> Record (ConstructorPayload n s)
-> Maybe (Record (ConstructorPayload n s))
forall a. a -> Maybe a
Just (Rep Identity () -> Record (ConstructorPayload n s)
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep ([Identity Any] -> Rep Identity ()
forall {k} (f :: * -> *) (a :: k). [f Any] -> Rep f a
productRep [Identity Any]
vals))
Maybe [Identity Any]
Nothing -> Maybe (Record (ConstructorPayload n s))
forall a. Maybe a
Nothing
pattern Variant :: forall (n :: Symbol) (s :: SumRow).
ConstructorIndex n s
=> Field n -> Record (ConstructorPayload n s) -> Variant s
pattern $bVariant :: forall (n :: Symbol) (s :: SumRow).
ConstructorIndex n s =>
Field n -> Record (ConstructorPayload n s) -> Variant s
$mVariant :: forall {r} {n :: Symbol} {s :: SumRow}.
ConstructorIndex n s =>
Variant s
-> (Field n -> Record (ConstructorPayload n s) -> r)
-> ((# #) -> r)
-> r
Variant f r <- ( (\Variant s
v -> (Field n
forall (n :: Symbol). Field n
Field :: Field n, Field n -> Variant s -> Maybe (Record (ConstructorPayload n s))
forall (n :: Symbol) (s :: SumRow).
ConstructorIndex n s =>
Field n -> Variant s -> Maybe (Record (ConstructorPayload n s))
projectVariant (Field n
forall (n :: Symbol). Field n
Field :: Field n) Variant s
v)) -> (f, Just r) )
where Variant Field n
f Record (ConstructorPayload n s)
r = Field n -> Record (ConstructorPayload n s) -> Variant s
forall (n :: Symbol) (s :: SumRow) (fs :: ProductRow f).
ConstructorIndex n s =>
Field n -> Record fs -> Variant s
injectVariant Field n
f Record (ConstructorPayload n s)
r
projectRecordF :: forall (f :: Type -> Type) (sub :: ProductRow f) (super :: ProductRow f).
SubRow sub super => RecordF f super -> RecordF f sub
projectRecordF :: forall (f :: * -> *) (sub :: ProductRow f) (super :: ProductRow f).
SubRow sub super =>
RecordF f super -> RecordF f sub
projectRecordF (RowRep Rep f ()
rep) =
let vals :: SmallArray (f Any)
vals = Rep f () -> SmallArray (f Any)
forall {k} (f :: * -> *) (a :: k). Rep f a -> SmallArray (f Any)
repVals Rep f ()
rep
idxs :: [Int]
idxs = forall (sub :: ProductRow f) (super :: ProductRow f).
SubRow sub super =>
[Int]
forall {k1} {k2} (sub :: k1) (super :: k2).
SubRow sub super =>
[Int]
subRowIndices @sub @super
newSlots :: [f Any]
newSlots = [ SmallArray (f Any) -> Int -> f Any
forall a. SmallArray a -> Int -> a
indexSmallArray SmallArray (f Any)
vals Int
i | Int
i <- [Int]
idxs ]
in Rep f () -> RowRep f 'ProductRowHKDT sub ()
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep ([f Any] -> Rep f ()
forall {k} (f :: * -> *) (a :: k). [f Any] -> Rep f a
productRep [f Any]
newSlots)
projectRecord :: forall sub super. SubRow sub super => Record super -> Record sub
projectRecord :: forall (sub :: ProductRow f) (super :: ProductRow f).
SubRow sub super =>
Record super -> Record sub
projectRecord (RowRep Rep Identity ()
rep) =
let vals :: SmallArray (Identity Any)
vals = Rep Identity () -> SmallArray (Identity Any)
forall {k} (f :: * -> *) (a :: k). Rep f a -> SmallArray (f Any)
repVals Rep Identity ()
rep
idxs :: [Int]
idxs = forall (sub :: ProductRow f) (super :: ProductRow f).
SubRow sub super =>
[Int]
forall {k1} {k2} (sub :: k1) (super :: k2).
SubRow sub super =>
[Int]
subRowIndices @sub @super
newSlots :: [Identity Any]
newSlots = [ SmallArray (Identity Any) -> Int -> Identity Any
forall a. SmallArray a -> Int -> a
indexSmallArray SmallArray (Identity Any)
vals Int
i | Int
i <- [Int]
idxs ]
in Rep Identity () -> RowRep Identity 'ProductRowT sub ()
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep ([Identity Any] -> Rep Identity ()
forall {k} (f :: * -> *) (a :: k). [f Any] -> Rep f a
productRep [Identity Any]
newSlots)
widenVariantF :: forall (f :: Type -> Type) (sub :: SumRowHKD f) (super :: SumRowHKD f).
SubSum sub super => VariantF f sub -> VariantF f super
widenVariantF :: forall (f :: * -> *) (sub :: SumRow) (super :: SumRow).
SubSum sub super =>
VariantF f sub -> VariantF f super
widenVariantF (RowRep Rep f ()
rep) =
let tag :: Int
tag = Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Rep f () -> Word
forall {k} (f :: * -> *) (a :: k). Rep f a -> Word
repTag Rep f ()
rep) :: Int
superTag :: Word
superTag = (forall (sub :: SumRow) (super :: SumRow).
SubSum sub super =>
[Word]
forall {k1} {k2} (sub :: k1) (super :: k2).
SubSum sub super =>
[Word]
subSumInjectIndices @sub @super) [Word] -> Int -> Word
forall a. HasCallStack => [a] -> Int -> a
!! Int
tag
in Rep f () -> RowRep f 'SumRowHKDT super ()
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep (Word -> SmallArray (f Any) -> Rep f ()
forall {k} (f :: * -> *) (a :: k).
Word -> SmallArray (f Any) -> Rep f a
Rep Word
superTag (Rep f () -> SmallArray (f Any)
forall {k} (f :: * -> *) (a :: k). Rep f a -> SmallArray (f Any)
repVals Rep f ()
rep))
widenVariant :: forall sub super. SubSum sub super => Variant sub -> Variant super
widenVariant :: forall (sub :: SumRow) (super :: SumRow).
SubSum sub super =>
Variant sub -> Variant super
widenVariant (RowRep Rep Identity ()
rep) =
let tag :: Int
tag = Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Rep Identity () -> Word
forall {k} (f :: * -> *) (a :: k). Rep f a -> Word
repTag Rep Identity ()
rep) :: Int
superTag :: Word
superTag = (forall (sub :: SumRow) (super :: SumRow).
SubSum sub super =>
[Word]
forall {k1} {k2} (sub :: k1) (super :: k2).
SubSum sub super =>
[Word]
subSumInjectIndices @sub @super) [Word] -> Int -> Word
forall a. HasCallStack => [a] -> Int -> a
!! Int
tag
in Rep Identity () -> RowRep Identity 'SumRowT super ()
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep (Word -> SmallArray (Identity Any) -> Rep Identity ()
forall {k} (f :: * -> *) (a :: k).
Word -> SmallArray (f Any) -> Rep f a
Rep Word
superTag (Rep Identity () -> SmallArray (Identity Any)
forall {k} (f :: * -> *) (a :: k). Rep f a -> SmallArray (f Any)
repVals Rep Identity ()
rep))
narrowVariantF :: forall (f :: Type -> Type) (sub :: SumRowHKD f) (super :: SumRowHKD f).
SubSum sub super => VariantF f super -> Maybe (VariantF f sub)
narrowVariantF :: forall (f :: * -> *) (sub :: SumRow) (super :: SumRow).
SubSum sub super =>
VariantF f super -> Maybe (VariantF f sub)
narrowVariantF (RowRep Rep f ()
rep) =
let tag :: Int
tag = Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Rep f () -> Word
forall {k} (f :: * -> *) (a :: k). Rep f a -> Word
repTag Rep f ()
rep) :: Int
narrowMap :: [Maybe Word]
narrowMap = forall (sub :: SumRow) (super :: SumRow).
SubSum sub super =>
[Maybe Word]
forall {k1} {k2} (sub :: k1) (super :: k2).
SubSum sub super =>
[Maybe Word]
subSumNarrowIndices @sub @super
in case Int -> [Maybe Word] -> [Maybe Word]
forall a. Int -> [a] -> [a]
drop Int
tag [Maybe Word]
narrowMap of
(Just Word
subTag : [Maybe Word]
_) -> VariantF f sub -> Maybe (VariantF f sub)
forall a. a -> Maybe a
Just (Rep f () -> VariantF f sub
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep (Word -> SmallArray (f Any) -> Rep f ()
forall {k} (f :: * -> *) (a :: k).
Word -> SmallArray (f Any) -> Rep f a
Rep Word
subTag (Rep f () -> SmallArray (f Any)
forall {k} (f :: * -> *) (a :: k). Rep f a -> SmallArray (f Any)
repVals Rep f ()
rep)))
[Maybe Word]
_ -> Maybe (VariantF f sub)
forall a. Maybe a
Nothing
narrowVariant :: forall sub super. SubSum sub super => Variant super -> Maybe (Variant sub)
narrowVariant :: forall (sub :: SumRow) (super :: SumRow).
SubSum sub super =>
Variant super -> Maybe (Variant sub)
narrowVariant (RowRep Rep Identity ()
rep) =
let tag :: Int
tag = Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Rep Identity () -> Word
forall {k} (f :: * -> *) (a :: k). Rep f a -> Word
repTag Rep Identity ()
rep) :: Int
narrowMap :: [Maybe Word]
narrowMap = forall (sub :: SumRow) (super :: SumRow).
SubSum sub super =>
[Maybe Word]
forall {k1} {k2} (sub :: k1) (super :: k2).
SubSum sub super =>
[Maybe Word]
subSumNarrowIndices @sub @super
in case Int -> [Maybe Word] -> [Maybe Word]
forall a. Int -> [a] -> [a]
drop Int
tag [Maybe Word]
narrowMap of
(Just Word
subTag : [Maybe Word]
_) -> Variant sub -> Maybe (Variant sub)
forall a. a -> Maybe a
Just (Rep Identity () -> Variant sub
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep (Word -> SmallArray (Identity Any) -> Rep Identity ()
forall {k} (f :: * -> *) (a :: k).
Word -> SmallArray (f Any) -> Rep f a
Rep Word
subTag (Rep Identity () -> SmallArray (Identity Any)
forall {k} (f :: * -> *) (a :: k). Rep f a -> SmallArray (f Any)
repVals Rep Identity ()
rep)))
[Maybe Word]
_ -> Maybe (Variant sub)
forall a. Maybe a
Nothing
type family Delete (n :: Symbol) (s :: [Pair Symbol k]) :: [Pair Symbol k] where
Delete n ((n ':= fs) ': rest) = rest
Delete n ((m ':= fs) ': rest) = (m ':= fs) ': Delete n rest
Delete n '[] = '[]
peel :: forall (n :: Symbol) (s :: SumRow).
ConstructorIndex n s
=> Variant s
-> Either (Variant (Delete n s)) (Record (ConstructorPayload n s))
peel :: forall (n :: Symbol) (s :: SumRow).
ConstructorIndex n s =>
Variant s
-> Either (Variant (Delete n s)) (Record (ConstructorPayload n s))
peel (RowRep Rep Identity ()
r) =
case Word -> Rep Identity () -> Either (Rep Identity ()) [Identity Any]
forall {k} (f :: * -> *) (a :: k).
Word -> Rep f a -> Either (Rep f a) [f Any]
peelRep (forall {kn} k (n :: kn) (row :: k). ConstructorIndex n row => Word
forall k (n :: Symbol) (row :: k). ConstructorIndex n row => Word
constructorIndex @_ @n @s) Rep Identity ()
r of
Right [Identity Any]
vals -> Record (ConstructorPayload n s)
-> Either (Variant (Delete n s)) (Record (ConstructorPayload n s))
forall a b. b -> Either a b
Right (Rep Identity () -> Record (ConstructorPayload n s)
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep ([Identity Any] -> Rep Identity ()
forall {k} (f :: * -> *) (a :: k). [f Any] -> Rep f a
productRep [Identity Any]
vals))
Left Rep Identity ()
remR -> Variant (Delete n s)
-> Either (Variant (Delete n s)) (Record (ConstructorPayload n s))
forall a b. a -> Either a b
Left (Rep Identity () -> Variant (Delete n s)
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep Rep Identity ()
remR)
peelF :: forall (n :: Symbol) (f :: Type -> Type) (s :: SumRowHKD f).
ConstructorIndex n s
=> VariantF f s
-> Either (VariantF f (Delete n s)) (RecordF f (ConstructorPayloadHKD f n s))
peelF :: forall (n :: Symbol) (f :: * -> *) (s :: SumRow).
ConstructorIndex n s =>
VariantF f s
-> Either
(VariantF f (Delete n s)) (RecordF f (ConstructorPayloadHKD f n s))
peelF (RowRep Rep f ()
r) =
case Word -> Rep f () -> Either (Rep f ()) [f Any]
forall {k} (f :: * -> *) (a :: k).
Word -> Rep f a -> Either (Rep f a) [f Any]
peelRep (forall {kn} k (n :: kn) (row :: k). ConstructorIndex n row => Word
forall k (n :: Symbol) (row :: k). ConstructorIndex n row => Word
constructorIndex @_ @n @s) Rep f ()
r of
Right [f Any]
vals -> RecordF f (ConstructorPayloadHKD f n s)
-> Either
(VariantF f (Delete n s)) (RecordF f (ConstructorPayloadHKD f n s))
forall a b. b -> Either a b
Right (Rep f () -> RecordF f (ConstructorPayloadHKD f n s)
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep ([f Any] -> Rep f ()
forall {k} (f :: * -> *) (a :: k). [f Any] -> Rep f a
productRep [f Any]
vals))
Left Rep f ()
remR -> VariantF f (Delete n s)
-> Either
(VariantF f (Delete n s)) (RecordF f (ConstructorPayloadHKD f n s))
forall a b. a -> Either a b
Left (Rep f () -> VariantF f (Delete n s)
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep Rep f ()
remR)
type family HandlerRecordRow (s :: SumRow) (res :: Type) :: Row where
HandlerRecordRow '[] _ = '[]
HandlerRecordRow ((n ':= fs) ': rest) res = (n ':= (Record fs -> res)) ': HandlerRecordRow rest res
type family HandlerRecordRowM (s :: SumRow) (m :: Type -> Type) (res :: Type) :: Row where
HandlerRecordRowM '[] _ _ = '[]
HandlerRecordRowM ((n ':= fs) ': rest) m res = (n ':= (Record fs -> m res)) ': HandlerRecordRowM rest m res
type family HandlerRecordRowHetero (s :: SumRow) (resRow :: SumRow) :: Row where
HandlerRecordRowHetero '[] _ = '[]
HandlerRecordRowHetero ((n ':= fs) ': rest) ((n ':= rfs) ': rrest) =
(n ':= (Record fs -> Record rfs)) ': HandlerRecordRowHetero rest rrest
type family HandlerRecordRowHeteroM (s :: SumRow) (resRow :: SumRow) (m :: Type -> Type) :: Row where
HandlerRecordRowHeteroM '[] _ _ = '[]
HandlerRecordRowHeteroM ((n ':= fs) ': rest) ((n ':= rfs) ': rrest) m =
(n ':= (Record fs -> m (Record rfs))) ': HandlerRecordRowHeteroM rest rrest m
eliminateUniform :: forall (s :: SumRow) a.
Record (HandlerRecordRow s a)
-> Variant s
-> a
eliminateUniform :: forall (s :: SumRow) a.
Record (HandlerRecordRow s a) -> Variant s -> a
eliminateUniform (RowRep (Rep Word
_ SmallArray (Identity Any)
hVals)) (RowRep (Rep Word
tag SmallArray (Identity Any)
vals)) =
let Identity Any
hAny = SmallArray (Identity Any) -> Int -> Identity Any
forall a. SmallArray a -> Int -> a
indexSmallArray SmallArray (Identity Any)
hVals (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
tag)
h :: Record '[] -> a
h = Any -> Record '[] -> a
forall a b. a -> b
unsafeCoerce Any
hAny :: Record '[] -> a
payload :: Record '[]
payload = Rep Identity () -> Record '[]
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep (Word -> SmallArray (Identity Any) -> Rep Identity ()
forall {k} (f :: * -> *) (a :: k).
Word -> SmallArray (f Any) -> Rep f a
Rep Word
0 SmallArray (Identity Any)
vals) :: Record '[]
in Record '[] -> a
h Record '[]
payload
eliminateUniformM :: forall (s :: SumRow) m a.
Record (HandlerRecordRowM s m a)
-> Variant s
-> m a
eliminateUniformM :: forall (s :: SumRow) (m :: * -> *) a.
Record (HandlerRecordRowM s m a) -> Variant s -> m a
eliminateUniformM (RowRep (Rep Word
_ SmallArray (Identity Any)
hVals)) (RowRep (Rep Word
tag SmallArray (Identity Any)
vals)) =
let Identity Any
hAny = SmallArray (Identity Any) -> Int -> Identity Any
forall a. SmallArray a -> Int -> a
indexSmallArray SmallArray (Identity Any)
hVals (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
tag)
h :: Record '[] -> m a
h = Any -> Record '[] -> m a
forall a b. a -> b
unsafeCoerce Any
hAny :: Record '[] -> m a
payload :: Record '[]
payload = Rep Identity () -> Record '[]
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep (Word -> SmallArray (Identity Any) -> Rep Identity ()
forall {k} (f :: * -> *) (a :: k).
Word -> SmallArray (f Any) -> Rep f a
Rep Word
0 SmallArray (Identity Any)
vals) :: Record '[]
in Record '[] -> m a
h Record '[]
payload
eliminate :: forall (s :: SumRow) (resRow :: SumRow).
Record (HandlerRecordRowHetero s resRow)
-> Variant s
-> Variant resRow
eliminate :: forall (s :: SumRow) (resRow :: SumRow).
Record (HandlerRecordRowHetero s resRow)
-> Variant s -> Variant resRow
eliminate (RowRep (Rep Word
_ SmallArray (Identity Any)
hVals)) (RowRep (Rep Word
tag SmallArray (Identity Any)
vals)) =
let Identity Any
hAny = SmallArray (Identity Any) -> Int -> Identity Any
forall a. SmallArray a -> Int -> a
indexSmallArray SmallArray (Identity Any)
hVals (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
tag)
h :: Record '[] -> Record '[]
h = Any -> Record '[] -> Record '[]
forall a b. a -> b
unsafeCoerce Any
hAny :: Record '[] -> Record '[]
payload :: Record '[]
payload = Rep Identity () -> Record '[]
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep (Word -> SmallArray (Identity Any) -> Rep Identity ()
forall {k} (f :: * -> *) (a :: k).
Word -> SmallArray (f Any) -> Rep f a
Rep Word
0 SmallArray (Identity Any)
vals) :: Record '[]
RowRep (Rep Word
_ SmallArray (Identity Any)
resVals) = Record '[] -> Record '[]
h Record '[]
payload
in Rep Identity () -> RowRep Identity 'SumRowT resRow ()
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep (Word -> SmallArray (Identity Any) -> Rep Identity ()
forall {k} (f :: * -> *) (a :: k).
Word -> SmallArray (f Any) -> Rep f a
Rep Word
tag SmallArray (Identity Any)
resVals)
eliminateM :: forall (s :: SumRow) (resRow :: SumRow) m.
Monad m
=> Record (HandlerRecordRowHeteroM s resRow m)
-> Variant s
-> m (Variant resRow)
eliminateM :: forall (s :: SumRow) (resRow :: SumRow) (m :: * -> *).
Monad m =>
Record (HandlerRecordRowHeteroM s resRow m)
-> Variant s -> m (Variant resRow)
eliminateM (RowRep (Rep Word
_ SmallArray (Identity Any)
hVals)) (RowRep (Rep Word
tag SmallArray (Identity Any)
vals)) =
let Identity Any
hAny = SmallArray (Identity Any) -> Int -> Identity Any
forall a. SmallArray a -> Int -> a
indexSmallArray SmallArray (Identity Any)
hVals (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
tag)
h :: Record '[] -> m (Record '[])
h = Any -> Record '[] -> m (Record '[])
forall a b. a -> b
unsafeCoerce Any
hAny :: Record '[] -> m (Record '[])
payload :: Record '[]
payload = Rep Identity () -> Record '[]
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep (Word -> SmallArray (Identity Any) -> Rep Identity ()
forall {k} (f :: * -> *) (a :: k).
Word -> SmallArray (f Any) -> Rep f a
Rep Word
0 SmallArray (Identity Any)
vals) :: Record '[]
in do
RowRep (Rep _ resVals) <- Record '[] -> m (Record '[])
h Record '[]
payload
pure (RowRep (Rep tag resVals))
matchVariant :: forall (s :: SumRow) a.
Variant s
-> Record (HandlerRecordRow s a)
-> a
matchVariant :: forall (s :: SumRow) a.
Variant s -> Record (HandlerRecordRow s a) -> a
matchVariant = (Record (HandlerRecordRow s a) -> Variant s -> a)
-> Variant s -> Record (HandlerRecordRow s a) -> a
forall a b c. (a -> b -> c) -> b -> a -> c
flip Record (HandlerRecordRow s a) -> Variant s -> a
forall (s :: SumRow) a.
Record (HandlerRecordRow s a) -> Variant s -> a
eliminateUniform
data REC = REC
deriving (Int -> REC -> ShowS
[REC] -> ShowS
REC -> String
(Int -> REC -> ShowS)
-> (REC -> String) -> ([REC] -> ShowS) -> Show REC
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> REC -> ShowS
showsPrec :: Int -> REC -> ShowS
$cshow :: REC -> String
show :: REC -> String
$cshowList :: [REC] -> ShowS
showList :: [REC] -> ShowS
Show, REC -> REC -> Bool
(REC -> REC -> Bool) -> (REC -> REC -> Bool) -> Eq REC
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: REC -> REC -> Bool
== :: REC -> REC -> Bool
$c/= :: REC -> REC -> Bool
/= :: REC -> REC -> Bool
Eq)
data REC_F = REC_F
deriving (Int -> REC_F -> ShowS
[REC_F] -> ShowS
REC_F -> String
(Int -> REC_F -> ShowS)
-> (REC_F -> String) -> ([REC_F] -> ShowS) -> Show REC_F
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> REC_F -> ShowS
showsPrec :: Int -> REC_F -> ShowS
$cshow :: REC_F -> String
show :: REC_F -> String
$cshowList :: [REC_F] -> ShowS
showList :: [REC_F] -> ShowS
Show, REC_F -> REC_F -> Bool
(REC_F -> REC_F -> Bool) -> (REC_F -> REC_F -> Bool) -> Eq REC_F
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: REC_F -> REC_F -> Bool
== :: REC_F -> REC_F -> Bool
$c/= :: REC_F -> REC_F -> Bool
/= :: REC_F -> REC_F -> Bool
Eq)
data VAR = VAR
deriving (Int -> VAR -> ShowS
[VAR] -> ShowS
VAR -> String
(Int -> VAR -> ShowS)
-> (VAR -> String) -> ([VAR] -> ShowS) -> Show VAR
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VAR -> ShowS
showsPrec :: Int -> VAR -> ShowS
$cshow :: VAR -> String
show :: VAR -> String
$cshowList :: [VAR] -> ShowS
showList :: [VAR] -> ShowS
Show, VAR -> VAR -> Bool
(VAR -> VAR -> Bool) -> (VAR -> VAR -> Bool) -> Eq VAR
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VAR -> VAR -> Bool
== :: VAR -> VAR -> Bool
$c/= :: VAR -> VAR -> Bool
/= :: VAR -> VAR -> Bool
Eq)
type VARIANT = VAR
pattern VARIANT :: VAR
pattern $bVARIANT :: VAR
$mVARIANT :: forall {r}. VAR -> ((# #) -> r) -> ((# #) -> r) -> r
VARIANT = VAR
data REC_UPD = REC_UPD
deriving (Int -> REC_UPD -> ShowS
[REC_UPD] -> ShowS
REC_UPD -> String
(Int -> REC_UPD -> ShowS)
-> (REC_UPD -> String) -> ([REC_UPD] -> ShowS) -> Show REC_UPD
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> REC_UPD -> ShowS
showsPrec :: Int -> REC_UPD -> ShowS
$cshow :: REC_UPD -> String
show :: REC_UPD -> String
$cshowList :: [REC_UPD] -> ShowS
showList :: [REC_UPD] -> ShowS
Show, REC_UPD -> REC_UPD -> Bool
(REC_UPD -> REC_UPD -> Bool)
-> (REC_UPD -> REC_UPD -> Bool) -> Eq REC_UPD
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: REC_UPD -> REC_UPD -> Bool
== :: REC_UPD -> REC_UPD -> Bool
$c/= :: REC_UPD -> REC_UPD -> Bool
/= :: REC_UPD -> REC_UPD -> Bool
Eq)
data REC_UPD_F = REC_UPD_F
deriving (Int -> REC_UPD_F -> ShowS
[REC_UPD_F] -> ShowS
REC_UPD_F -> String
(Int -> REC_UPD_F -> ShowS)
-> (REC_UPD_F -> String)
-> ([REC_UPD_F] -> ShowS)
-> Show REC_UPD_F
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> REC_UPD_F -> ShowS
showsPrec :: Int -> REC_UPD_F -> ShowS
$cshow :: REC_UPD_F -> String
show :: REC_UPD_F -> String
$cshowList :: [REC_UPD_F] -> ShowS
showList :: [REC_UPD_F] -> ShowS
Show, REC_UPD_F -> REC_UPD_F -> Bool
(REC_UPD_F -> REC_UPD_F -> Bool)
-> (REC_UPD_F -> REC_UPD_F -> Bool) -> Eq REC_UPD_F
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: REC_UPD_F -> REC_UPD_F -> Bool
== :: REC_UPD_F -> REC_UPD_F -> Bool
$c/= :: REC_UPD_F -> REC_UPD_F -> Bool
/= :: REC_UPD_F -> REC_UPD_F -> Bool
Eq)
class OpenRecord a
class OpenVariant a
recordField :: forall n a r. HasField n (Record r) (Identity a) => Field n -> Record r -> a
recordField :: forall (n :: Symbol) a (r :: ProductRow f).
HasField n (Record r) (Identity a) =>
Field n -> Record r -> a
recordField Field n
_ Record r
r = case forall {k} (x :: k) r a. HasField x r a => r -> a
forall (x :: Symbol) r a. HasField x r a => r -> a
getField @n Record r
r of Identity a
x -> a
x
setField :: forall n a r. FieldIndex n r a => Field n -> a -> Record r -> Record r
setField :: forall (n :: Symbol) a (r :: ProductRow f).
FieldIndex n r a =>
Field n -> a -> Record r -> Record r
setField Field n
_ a
val (RowRep Rep Identity ()
rep) =
Rep Identity () -> RowRep Identity 'ProductRowT r ()
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep (Int -> Identity Any -> Rep Identity () -> Rep Identity ()
forall {k} (f :: * -> *) (a :: k).
Int -> f Any -> Rep f a -> Rep f a
setFieldAt (forall {kn} k {ka} (n :: kn) (row :: k) (a :: ka).
FieldIndex n row a =>
Int
forall k {ka} (n :: Symbol) (row :: k) (a :: ka).
FieldIndex n row a =>
Int
fieldIndex @_ @n @r @a) (Any -> Identity Any
forall a. a -> Identity a
Identity (a -> Any
forall a b. a -> b
noInlineUnsafeCo a
val)) Rep Identity ()
rep)
setFieldF :: forall n a f r. FieldIndex n r (f a) => Field n -> f a -> RecordF f r -> RecordF f r
setFieldF :: forall (n :: Symbol) a (f :: * -> *) (r :: ProductRow f).
FieldIndex n r (f a) =>
Field n -> f a -> RecordF f r -> RecordF f r
setFieldF Field n
_ f a
val (RowRep Rep f ()
rep) =
Rep f () -> RowRep f 'ProductRowHKDT r ()
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep (Int -> f Any -> Rep f () -> Rep f ()
forall {k} (f :: * -> *) (a :: k).
Int -> f Any -> Rep f a -> Rep f a
setFieldAt (forall {kn} k {ka} (n :: kn) (row :: k) (a :: ka).
FieldIndex n row a =>
Int
forall k {ka} (n :: Symbol) (row :: k) (a :: ka).
FieldIndex n row a =>
Int
fieldIndex @_ @n @r @(f a)) (f a -> f Any
forall a b. a -> b
noInlineUnsafeCo f a
val) Rep f ()
rep)
cmapRecord
:: forall c r. AllFields ProductRowT r c
=> (forall x. c x => x -> x)
-> Record r
-> Record r
cmapRecord :: forall (c :: * -> Constraint) (r :: ProductRow f).
AllFields 'ProductRowT r c =>
(forall x. c x => x -> x) -> Record r -> Record r
cmapRecord forall x. c x => x -> x
f (RowRep (Rep Word
t SmallArray (Identity Any)
v)) =
let dicts :: DictAllFields c
dicts = forall {k} (r :: RowType) (row :: k) (c :: * -> Constraint).
AllFields r row c =>
DictAllFields c
forall (r :: RowType) (row :: ProductRow f) (c :: * -> Constraint).
AllFields r row c =>
DictAllFields c
fieldDicts @ProductRowT @r @c
n :: Int
n = SmallArray (Identity Any) -> Int
forall a. SmallArray a -> Int
sizeofSmallArray SmallArray (Identity Any)
v
v' :: SmallArray (Identity Any)
v' = (forall s. ST s (SmallMutableArray s (Identity Any)))
-> SmallArray (Identity Any)
forall a. (forall s. ST s (SmallMutableArray s a)) -> SmallArray a
runSmallArray ((forall s. ST s (SmallMutableArray s (Identity Any)))
-> SmallArray (Identity Any))
-> (forall s. ST s (SmallMutableArray s (Identity Any)))
-> SmallArray (Identity Any)
forall a b. (a -> b) -> a -> b
$ do
m <- SmallArray (Identity Any)
-> Int
-> Int
-> ST s (SmallMutableArray (PrimState (ST s)) (Identity Any))
forall (m :: * -> *) a.
PrimMonad m =>
SmallArray a -> Int -> Int -> m (SmallMutableArray (PrimState m) a)
thawSmallArray SmallArray (Identity Any)
v Int
0 Int
n
let loop Int
i
| Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n = () -> ST s ()
forall a. a -> ST s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
| Bool
otherwise = do
let d :: DictAny c
d = DictAllFields c -> Int -> DictAny c
forall a. SmallArray a -> Int -> a
indexSmallArray DictAllFields c
dicts Int
i
Identity Any
vi = SmallArray (Identity Any) -> Int -> Identity Any
forall a. SmallArray a -> Int -> a
indexSmallArray SmallArray (Identity Any)
v Int
i
case DictAny c
d of
DictAny c
DictAny -> do
let vi' :: Any
vi' = Any -> Any
forall x. c x => x -> x
f (Any -> Any
forall a b. a -> b
noInlineUnsafeCo Any
vi :: Any)
SmallMutableArray (PrimState (ST s)) (Identity Any)
-> Int -> Identity Any -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> Int -> a -> m ()
writeSmallArray SmallMutableArray s (Identity Any)
SmallMutableArray (PrimState (ST s)) (Identity Any)
m Int
i (Any -> Identity Any
forall a. a -> Identity a
Identity (Any -> Any
forall a b. a -> b
noInlineUnsafeCo Any
vi'))
Int -> ST s ()
loop (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
loop 0
pure m
in Rep Identity () -> RowRep Identity 'ProductRowT r ()
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep (Word -> SmallArray (Identity Any) -> Rep Identity ()
forall {k} (f :: * -> *) (a :: k).
Word -> SmallArray (f Any) -> Rep f a
Rep Word
t SmallArray (Identity Any)
v')
cfoldMapRecord
:: forall c r m. (AllFields ProductRowT r c, Monoid m)
=> (forall x. c x => x -> m)
-> Record r
-> m
cfoldMapRecord :: forall (c :: * -> Constraint) (r :: ProductRow f) m.
(AllFields 'ProductRowT r c, Monoid m) =>
(forall x. c x => x -> m) -> Record r -> m
cfoldMapRecord forall x. c x => x -> m
f (RowRep (Rep Word
_ SmallArray (Identity Any)
v)) =
let dicts :: DictAllFields c
dicts = forall {k} (r :: RowType) (row :: k) (c :: * -> Constraint).
AllFields r row c =>
DictAllFields c
forall (r :: RowType) (row :: ProductRow f) (c :: * -> Constraint).
AllFields r row c =>
DictAllFields c
fieldDicts @ProductRowT @r @c
n :: Int
n = SmallArray (Identity Any) -> Int
forall a. SmallArray a -> Int
sizeofSmallArray SmallArray (Identity Any)
v
loop :: Int -> m
loop Int
i
| Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n = m
forall a. Monoid a => a
mempty
| Bool
otherwise =
let d :: DictAny c
d = DictAllFields c -> Int -> DictAny c
forall a. SmallArray a -> Int -> a
indexSmallArray DictAllFields c
dicts Int
i
Identity Any
vi = SmallArray (Identity Any) -> Int -> Identity Any
forall a. SmallArray a -> Int -> a
indexSmallArray SmallArray (Identity Any)
v Int
i
in case DictAny c
d of
DictAny c
DictAny ->
let val :: m
val = Any -> m
forall x. c x => x -> m
f (Any -> Any
forall a b. a -> b
noInlineUnsafeCo Any
vi :: Any)
in m
val m -> m -> m
forall a. Semigroup a => a -> a -> a
<> Int -> m
loop (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
in Int -> m
loop Int
0
czipWithRecord
:: forall c r. AllFields ProductRowT r c
=> (forall x. c x => x -> x -> x)
-> Record r
-> Record r
-> Record r
czipWithRecord :: forall (c :: * -> Constraint) (r :: ProductRow f).
AllFields 'ProductRowT r c =>
(forall x. c x => x -> x -> x) -> Record r -> Record r -> Record r
czipWithRecord forall x. c x => x -> x -> x
f (RowRep (Rep Word
t SmallArray (Identity Any)
v1)) (RowRep (Rep Word
_ SmallArray (Identity Any)
v2)) =
let dicts :: DictAllFields c
dicts = forall {k} (r :: RowType) (row :: k) (c :: * -> Constraint).
AllFields r row c =>
DictAllFields c
forall (r :: RowType) (row :: ProductRow f) (c :: * -> Constraint).
AllFields r row c =>
DictAllFields c
fieldDicts @ProductRowT @r @c
n :: Int
n = SmallArray (Identity Any) -> Int
forall a. SmallArray a -> Int
sizeofSmallArray SmallArray (Identity Any)
v1
v' :: SmallArray (Identity Any)
v' = (forall s. ST s (SmallMutableArray s (Identity Any)))
-> SmallArray (Identity Any)
forall a. (forall s. ST s (SmallMutableArray s a)) -> SmallArray a
runSmallArray ((forall s. ST s (SmallMutableArray s (Identity Any)))
-> SmallArray (Identity Any))
-> (forall s. ST s (SmallMutableArray s (Identity Any)))
-> SmallArray (Identity Any)
forall a b. (a -> b) -> a -> b
$ do
m <- SmallArray (Identity Any)
-> Int
-> Int
-> ST s (SmallMutableArray (PrimState (ST s)) (Identity Any))
forall (m :: * -> *) a.
PrimMonad m =>
SmallArray a -> Int -> Int -> m (SmallMutableArray (PrimState m) a)
thawSmallArray SmallArray (Identity Any)
v1 Int
0 Int
n
let loop Int
i
| Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n = () -> ST s ()
forall a. a -> ST s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
| Bool
otherwise = do
let d :: DictAny c
d = DictAllFields c -> Int -> DictAny c
forall a. SmallArray a -> Int -> a
indexSmallArray DictAllFields c
dicts Int
i
Identity Any
x1 = SmallArray (Identity Any) -> Int -> Identity Any
forall a. SmallArray a -> Int -> a
indexSmallArray SmallArray (Identity Any)
v1 Int
i
Identity Any
x2 = SmallArray (Identity Any) -> Int -> Identity Any
forall a. SmallArray a -> Int -> a
indexSmallArray SmallArray (Identity Any)
v2 Int
i
case DictAny c
d of
DictAny c
DictAny -> do
let res :: Any
res = Any -> Any -> Any
forall x. c x => x -> x -> x
f (Any -> Any
forall a b. a -> b
noInlineUnsafeCo Any
x1 :: Any) (Any -> Any
forall a b. a -> b
noInlineUnsafeCo Any
x2 :: Any)
SmallMutableArray (PrimState (ST s)) (Identity Any)
-> Int -> Identity Any -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> Int -> a -> m ()
writeSmallArray SmallMutableArray s (Identity Any)
SmallMutableArray (PrimState (ST s)) (Identity Any)
m Int
i (Any -> Identity Any
forall a. a -> Identity a
Identity (Any -> Any
forall a b. a -> b
noInlineUnsafeCo Any
res))
Int -> ST s ()
loop (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
loop 0
pure m
in Rep Identity () -> RowRep Identity 'ProductRowT r ()
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep (Word -> SmallArray (Identity Any) -> Rep Identity ()
forall {k} (f :: * -> *) (a :: k).
Word -> SmallArray (f Any) -> Rep f a
Rep Word
t SmallArray (Identity Any)
v')
cmapRecordF
:: forall c f r. AllFields ProductRowHKDT r c
=> (forall x. c x => x -> x)
-> RecordF f r
-> RecordF f r
cmapRecordF :: forall (c :: * -> Constraint) (f :: * -> *) (r :: ProductRow f).
AllFields 'ProductRowHKDT r c =>
(forall x. c x => x -> x) -> RecordF f r -> RecordF f r
cmapRecordF forall x. c x => x -> x
f (RowRep (Rep Word
t SmallArray (f Any)
v)) =
let dicts :: DictAllFields c
dicts = forall {k} (r :: RowType) (row :: k) (c :: * -> Constraint).
AllFields r row c =>
DictAllFields c
forall (r :: RowType) (row :: ProductRow f) (c :: * -> Constraint).
AllFields r row c =>
DictAllFields c
fieldDicts @ProductRowHKDT @r @c
n :: Int
n = SmallArray (f Any) -> Int
forall a. SmallArray a -> Int
sizeofSmallArray SmallArray (f Any)
v
v' :: SmallArray (f Any)
v' = (forall s. ST s (SmallMutableArray s (f Any)))
-> SmallArray (f Any)
forall a. (forall s. ST s (SmallMutableArray s a)) -> SmallArray a
runSmallArray ((forall s. ST s (SmallMutableArray s (f Any)))
-> SmallArray (f Any))
-> (forall s. ST s (SmallMutableArray s (f Any)))
-> SmallArray (f Any)
forall a b. (a -> b) -> a -> b
$ do
m <- SmallArray (f Any)
-> Int
-> Int
-> ST s (SmallMutableArray (PrimState (ST s)) (f Any))
forall (m :: * -> *) a.
PrimMonad m =>
SmallArray a -> Int -> Int -> m (SmallMutableArray (PrimState m) a)
thawSmallArray SmallArray (f Any)
v Int
0 Int
n
let loop Int
i
| Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n = () -> ST s ()
forall a. a -> ST s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
| Bool
otherwise = do
let d :: DictAny c
d = DictAllFields c -> Int -> DictAny c
forall a. SmallArray a -> Int -> a
indexSmallArray DictAllFields c
dicts Int
i
vi :: f Any
vi = SmallArray (f Any) -> Int -> f Any
forall a. SmallArray a -> Int -> a
indexSmallArray SmallArray (f Any)
v Int
i
case DictAny c
d of
DictAny c
DictAny -> do
let vi' :: Any
vi' = Any -> Any
forall x. c x => x -> x
f (f Any -> Any
forall a b. a -> b
noInlineUnsafeCo f Any
vi :: Any)
SmallMutableArray (PrimState (ST s)) (f Any)
-> Int -> f Any -> ST s ()
forall (m :: * -> *) a.
PrimMonad m =>
SmallMutableArray (PrimState m) a -> Int -> a -> m ()
writeSmallArray SmallMutableArray s (f Any)
SmallMutableArray (PrimState (ST s)) (f Any)
m Int
i (Any -> f Any
forall a b. a -> b
noInlineUnsafeCo Any
vi')
Int -> ST s ()
loop (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
loop 0
pure m
in Rep f () -> RowRep f 'ProductRowHKDT r ()
forall {k} k1 (f :: * -> *) (r :: RowType) (row :: k1) (a :: k).
Rep f a -> RowRep f r row a
RowRep (Word -> SmallArray (f Any) -> Rep f ()
forall {k} (f :: * -> *) (a :: k).
Word -> SmallArray (f Any) -> Rep f a
Rep Word
t SmallArray (f Any)
v')
cfoldMapRecordF
:: forall c f r m. (AllFields ProductRowHKDT r c, Monoid m)
=> (forall x. c x => x -> m)
-> RecordF f r
-> m
cfoldMapRecordF :: forall (c :: * -> Constraint) (f :: * -> *) (r :: ProductRow f) m.
(AllFields 'ProductRowHKDT r c, Monoid m) =>
(forall x. c x => x -> m) -> RecordF f r -> m
cfoldMapRecordF forall x. c x => x -> m
f (RowRep (Rep Word
_ SmallArray (f Any)
v)) =
let dicts :: DictAllFields c
dicts = forall {k} (r :: RowType) (row :: k) (c :: * -> Constraint).
AllFields r row c =>
DictAllFields c
forall (r :: RowType) (row :: ProductRow f) (c :: * -> Constraint).
AllFields r row c =>
DictAllFields c
fieldDicts @ProductRowHKDT @r @c
n :: Int
n = SmallArray (f Any) -> Int
forall a. SmallArray a -> Int
sizeofSmallArray SmallArray (f Any)
v
loop :: Int -> m
loop Int
i
| Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n = m
forall a. Monoid a => a
mempty
| Bool
otherwise =
let d :: DictAny c
d = DictAllFields c -> Int -> DictAny c
forall a. SmallArray a -> Int -> a
indexSmallArray DictAllFields c
dicts Int
i
vi :: f Any
vi = SmallArray (f Any) -> Int -> f Any
forall a. SmallArray a -> Int -> a
indexSmallArray SmallArray (f Any)
v Int
i
in case DictAny c
d of
DictAny c
DictAny ->
let val :: m
val = Any -> m
forall x. c x => x -> m
f (f Any -> Any
forall a b. a -> b
noInlineUnsafeCo f Any
vi :: Any)
in m
val m -> m -> m
forall a. Semigroup a => a -> a -> a
<> Int -> m
loop (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
in Int -> m
loop Int
0