module ADP.Fusion.Core.SynVar.Indices where
import Data.Proxy (Proxy(..))
import Data.Vector.Fusion.Stream.Monadic (map,Stream,head,mapM,flatten,Step(..))
import Prelude hiding (map,head,mapM)
import Data.PrimitiveArray hiding (map)
import ADP.Fusion.Core.Classes
import ADP.Fusion.Core.Multi
import ADP.Fusion.Core.TyLvlIx
class AddIndexDense pos elm minSize tableIx ix where
addIndexDenseGo
∷ (Monad m)
⇒ Proxy pos
→ minSize
→ LimitType tableIx
→ LimitType ix
→ ix
→ Stream m (SvState elm Z Z)
→ Stream m (SvState elm tableIx ix)
instance AddIndexDense pos elm Z Z Z where
addIndexDenseGo _ _ _ _ _ = id
{-# Inline addIndexDenseGo #-}
data SvState elm tableIx ix = SvS
{ sS ∷ !elm
, tx ∷ !tableIx
, iIx ∷ !(RunningIndex ix)
}
addIndexDense
∷ ( Monad m
, AddIndexDense pos elm minSize tableIx ix
, elm ~ Elm x0 i0
, Element x0 i0
)
⇒ Proxy pos
→ minSize
→ LimitType tableIx
→ LimitType ix
→ ix
→ Stream m elm
→ Stream m (elm,tableIx,RunningIndex ix)
addIndexDense pos minSize tableBound upperBound ix
= map (\(SvS s z i') -> (s,z,i'))
. addIndexDenseGo pos minSize tableBound upperBound ix
. map (\s -> (SvS s Z RiZ))
{-# Inline addIndexDense #-}
addIndexDense1
∷ forall m pos x0 a ix minSize tableIx elm
. ( Monad m
, AddIndexDense (Z:.pos) (Elm (SynVar1 (Elm x0 a)) (Z:.ix)) (Z:.minSize) (Z:.tableIx) (Z:.ix)
, GetIndex (Z:.a) (Z:.ix)
, elm ~ Elm x0 a
, Element x0 a
)
⇒ Proxy pos
→ minSize
→ LimitType tableIx
→ LimitType ix
→ ix
→ Stream m elm
→ Stream m (elm,tableIx,RunningIndex ix)
addIndexDense1 Proxy minSize tableBound upperBound ix
= map (\(SvS (ElmSynVar1 s) (Z:.z) (RiZ:.:i')) -> (s,z,i'))
. addIndexDenseGo (Proxy ∷ Proxy (Z:.pos)) (Z:.minSize) (ZZ:..tableBound) (ZZ:..upperBound) (Z:.ix)
. map (\s -> (SvS (elmSynVar1 s ix) Z RiZ))
{-# Inline addIndexDense1 #-}
newtype SynVar1 s = SynVar1 s
elmSynVar1 :: s -> i -> Elm (SynVar1 s) (Z:.i)
elmSynVar1 s _ = ElmSynVar1 s
{-# Inline elmSynVar1 #-}
instance (s ~ Elm x0 i, Element x0 i) => Element (SynVar1 s) (Z:.i) where
newtype Elm (SynVar1 s) (Z:.i) = ElmSynVar1 s
getIdx (ElmSynVar1 s) = RiZ :.: getIdx s
{-# Inline getIdx #-}
type AddIndexDenseContext pos elm x0 i0 minSizes minSize tableIxs tableIx ixs ix =
( AddIndexDense pos elm minSizes tableIxs ixs
, GetIndex (RunningIndex i0) (RunningIndex (ixs:.ix))
, GetIx (RunningIndex i0) (RunningIndex (ixs:.ix)) ~ (RunningIndex ix)
, Element x0 i0
, elm ~ Elm x0 i0
)