module ForSyDe.Process.SynchProc (
constSY, mapSY, zipWithSY, zipWith3SY,
zipWith4SY, zipWith5SY, zipWith6SY, zipWithxSY,
delaySY, delaynSY,
scanlSY, scanl2SY, scanl3SY, scanldSY, scanld2SY,
scanld3SY, mooreSY, moore2SY, moore3SY, mealySY,
mealy2SY, mealy3SY, sourceSY,
filterSY, fillSY, holdSY,
whenSY, zipSY, zip3SY, zip4SY, zip5SY, zip6SY,
unzipSY, unzip3SY, unzip4SY, unzip5SY, unzip6SY,
zipxSY, unzipxSY, mapxSY,
fstSY, sndSY, groupSY) where
import ForSyDe.Ids
import ForSyDe.System
import ForSyDe.Process.ProcType
import ForSyDe.Process.ProcType.Instances()
import ForSyDe.Process.ProcFun
import ForSyDe.Process.ProcVal
import ForSyDe.OSharing
import ForSyDe.Netlist
import ForSyDe.AbsentExt
import qualified Data.Param.FSVec as V
import Data.Param.FSVec hiding ((++), map)
import Data.TypeLevel (Nat, toInt)
import Data.Set (union)
import Data.Maybe
import Data.Dynamic
import Data.Typeable
constSY :: ProcType a =>
ProcId
-> a
-> Signal a
constSY id v = Signal (newNodeOutSig nodeRef ConstOut)
where nodeRef = newURef $ Proc id $ Const (mkProcVal v)
mapSY :: forall a b . (ProcType a, ProcType b) =>
ProcId
-> ProcFun (a -> b)
-> Signal a
-> Signal b
mapSY id f s = Signal (newNodeOutSig nodeRef ZipWithNSYOut)
where nodeRef = newURef $ Proc id $ ZipWithNSY dynPF [unSignal s]
dynPF = procFun2Dyn (getEnums (undefined ::a) `union`
getEnums (undefined ::b))
f
zipWithSY :: forall a b c . (ProcType a, ProcType b, ProcType c) =>
ProcId
-> ProcFun (a -> b -> c)
-> Signal a
-> Signal b
-> Signal c
zipWithSY id f s1 s2 = Signal (newNodeOutSig nodeRef ZipWithNSYOut)
where nodeRef = newURef $ Proc id $
ZipWithNSY dynPF [unSignal s1,unSignal s2]
dynPF = procFun2Dyn (getEnums (undefined ::a) `union`
getEnums (undefined ::b) `union`
getEnums (undefined ::c) )
f
zipWith3SY :: forall a b c d.
(ProcType a, ProcType b, ProcType c, ProcType d) =>
ProcId
-> ProcFun (a -> b -> c -> d)
-> Signal a
-> Signal b
-> Signal c
-> Signal d
zipWith3SY id f s1 s2 s3 = Signal (newNodeOutSig nodeRef ZipWithNSYOut)
where nodeRef = newURef $ Proc id $
ZipWithNSY dynPF
[unSignal s1,
unSignal s2,
unSignal s3]
dynPF = procFun2Dyn (getEnums (undefined ::a) `union`
getEnums (undefined ::b) `union`
getEnums (undefined ::c) `union`
getEnums (undefined ::d))
f
zipWith4SY ::forall a b c d e.
(ProcType a, ProcType b, ProcType c, ProcType d, ProcType e) =>
ProcId
-> ProcFun (a -> b -> c -> d -> e)
-> Signal a
-> Signal b
-> Signal c
-> Signal d
-> Signal e
zipWith4SY id f s1 s2 s3 s4 = Signal (newNodeOutSig nodeRef ZipWithNSYOut)
where nodeRef = newURef $ Proc id $
ZipWithNSY dynPF
[unSignal s1,
unSignal s2,
unSignal s3,
unSignal s4]
dynPF = procFun2Dyn (getEnums (undefined ::a) `union`
getEnums (undefined ::b) `union`
getEnums (undefined ::c) `union`
getEnums (undefined ::d) `union`
getEnums (undefined ::e) )
f
zipWith5SY :: forall a b c d e f.
(ProcType a, ProcType b, ProcType c, ProcType d, ProcType e,
ProcType f) =>
ProcId
-> ProcFun (a -> b -> c -> d -> e -> f)
-> Signal a
-> Signal b
-> Signal c
-> Signal d
-> Signal e
-> Signal f
zipWith5SY id f s1 s2 s3 s4 s5 = Signal (newNodeOutSig nodeRef ZipWithNSYOut)
where nodeRef = newURef $ Proc id $
ZipWithNSY dynPF
[unSignal s1,
unSignal s2,
unSignal s3,
unSignal s4,
unSignal s5]
dynPF = procFun2Dyn (getEnums (undefined ::a) `union`
getEnums (undefined ::b) `union`
getEnums (undefined ::c) `union`
getEnums (undefined ::d) `union`
getEnums (undefined ::e) `union`
getEnums (undefined ::f) )
f
zipWith6SY :: forall a b c d e f g.
(ProcType a, ProcType b, ProcType c, ProcType d, ProcType e,
ProcType f, ProcType g) =>
ProcId
-> ProcFun (a -> b -> c -> d -> e -> f -> g)
-> Signal a
-> Signal b
-> Signal c
-> Signal d
-> Signal e
-> Signal f
-> Signal g
zipWith6SY id f s1 s2 s3 s4 s5 s6 = Signal (newNodeOutSig nodeRef ZipWithNSYOut)
where nodeRef = newURef $ Proc id $
ZipWithNSY dynPF
[unSignal s1,
unSignal s2,
unSignal s3,
unSignal s4,
unSignal s5,
unSignal s6]
dynPF = procFun2Dyn (getEnums (undefined ::a) `union`
getEnums (undefined ::b) `union`
getEnums (undefined ::c) `union`
getEnums (undefined ::d) `union`
getEnums (undefined ::e) `union`
getEnums (undefined ::f) `union`
getEnums (undefined ::g) )
f
mapxSY :: (Nat s, ProcType a, ProcType b) =>
ProcId
-> ProcFun (a -> b)
-> FSVec s (Signal a)
-> FSVec s (Signal b)
mapxSY id f = V.zipWith (\n s -> mapSY (id ++ show n) f s)
(V.reallyUnsafeVector [(1::Int)..])
zipWithxSY :: forall s a b .
(Nat s, Typeable s, ProcType a, ProcType b) =>
ProcId
-> ProcFun (FSVec s a -> b)
-> FSVec s (Signal a)
-> Signal b
zipWithxSY id f sv = Signal (newNodeOutSig nodeRef ZipWithxSYOut)
where nodeRef = newURef $ Proc id $
ZipWithxSY (vecProcFun2List dynPF)
(map unSignal (V.fromVector sv))
vecProcFun2List :: TypedProcFun (FSVec s' a' -> b') ->
TypedProcFun ([a'] -> b')
vecProcFun2List f = f{tval = \x -> (tval f) (reallyUnsafeVector x)}
dynPF = contProcFun2Dyn (getEnums (undefined ::a) `union`
getEnums (undefined ::b) )
f
delaySY :: ProcType a =>
ProcId
-> a
-> Signal a
-> Signal a
delaySY id v s = Signal (newNodeOutSig nodeRef DelaySYOut)
where procVal = mkProcVal v
nodeRef = newURef $ Proc id $ DelaySY procVal (unSignal s)
delaynSY :: ProcType a =>
ProcId
-> a
-> Int
-> Signal a
-> Signal a
delaynSY id e n = instantiate id delaynSys
where delaynSys = newSysDef delaynSysF ("delay"++show n++"SY_"++id)
["in1"] ["out1"]
delaynSysF s = (\(a,_,_) -> a) $ delaynSYacum (s, 1, n)
delaynSYacum acum@(lastSig, curr, max)
| curr > max = acum
| otherwise =
delaynSYacum (delaySY ("delay" ++ show curr) e lastSig, curr+1, max)
scanlSY :: (ProcType a, ProcType b) =>
ProcId
-> ProcFun (a -> b -> a)
-> a
-> Signal b
-> Signal a
scanlSY id f mem = instantiate id scanlSys
where scanlSys = newSysDef scanlSysF ("scanlSY_"++id) ["in1"] ["out1"]
scanlSysF s = s'
where s' = zipWithSY "zipWith" f (delaySY "delay" mem s') s
scanl2SY :: (ProcType a, ProcType b, ProcType c) =>
ProcId
-> ProcFun (a -> b -> c -> a)
-> a
-> Signal b
-> Signal c
-> Signal a
scanl2SY id f mem = instantiate id scanl2Sys
where scanl2Sys = newSysDef scanl2SysF ("scanl2SY_"++id)
["in1", "in2"] ["out1"]
scanl2SysF s1 s2 = s'
where s' = zipWith3SY "zipWith" f (delaySY "delay" mem s') s1 s2
scanl3SY :: (ProcType a, ProcType b, ProcType c, ProcType d) =>
ProcId
-> ProcFun (a -> b -> c -> d -> a)
-> a
-> Signal b
-> Signal c
-> Signal d
-> Signal a
scanl3SY id f mem = instantiate id scanl3Sys
where scanl3Sys = newSysDef scanl3SysF ("scanl3SY_"++id)
["in1", "in2", "in3"] ["out1"]
scanl3SysF s1 s2 s3 = s'
where s' = zipWith4SY "zipWith" f (delaySY "delay" mem s') s1 s2 s3
scanldSY :: (ProcType a, ProcType b) =>
ProcId
-> ProcFun (a -> b -> a)
-> a
-> Signal b
-> Signal a
scanldSY id f mem = instantiate id scanldSys
where scanldSys = newSysDef scanldSysF ("scanlSY_"++id) ["in1"] ["out1"]
scanldSysF s = s'
where s' = delaySY "delay" mem $ zipWithSY "zipWith" f s' s
scanld2SY :: (ProcType a, ProcType b, ProcType c) =>
ProcId
-> ProcFun (a -> b -> c -> a)
-> a
-> Signal b
-> Signal c
-> Signal a
scanld2SY id f mem = instantiate id scanld2Sys
where scanld2Sys = newSysDef scanld2SysF ("scanld2SY_"++id)
["in1", "in2"] ["out1"]
scanld2SysF s1 s2 = s'
where s' = delaySY "delay" mem $ zipWith3SY "zipWith" f s' s1 s2
scanld3SY :: (ProcType a, ProcType b, ProcType c, ProcType d) =>
ProcId
-> ProcFun (a -> b -> c -> d -> a)
-> a
-> Signal b
-> Signal c
-> Signal d
-> Signal a
scanld3SY id f mem = instantiate id scanld3Sys
where scanld3Sys = newSysDef scanld3SysF ("scanld3SY_"++id)
["in1", "in2", "in3"] ["out1"]
scanld3SysF s1 s2 s3 = s'
where s' = delaySY "delay" mem $ zipWith4SY "zipWith" f s' s1 s2 s3
mooreSY :: (ProcType a, ProcType b, ProcType c) =>
ProcId
-> ProcFun (a -> b -> a)
-> ProcFun (a -> c)
-> a
-> Signal b
-> Signal c
mooreSY id nextState output initial = instantiate id mooreSys
where mooreSys = newSysDef mooreSysF ("mooreSY_"++id)
["in1"] ["out1"]
mooreSysF = mapSY "map" output . scanldSY "mooreScan" nextState initial
moore2SY :: (ProcType a, ProcType b, ProcType c, ProcType d) =>
ProcId
-> ProcFun (a -> b -> c -> a)
-> ProcFun (a -> d)
-> a
-> Signal b
-> Signal c
-> Signal d
moore2SY id nextState output initial = instantiate id moore2Sys
where moore2Sys = newSysDef moore2SysF ("moore2SY_"++id)
["in1", "in2"] ["out1"]
moore2SysF i1 i2 =
mapSY "map" output $ scanld2SY "mooreScan" nextState initial i1 i2
moore3SY :: (ProcType a, ProcType b, ProcType c, ProcType d, ProcType e) =>
ProcId
-> ProcFun (a -> b -> c -> d -> a)
-> ProcFun (a -> e)
-> a
-> Signal b
-> Signal c
-> Signal d
-> Signal e
moore3SY id nextState output initial = instantiate id moore3Sys
where moore3Sys = newSysDef moore3SysF ("moore3SY_"++id)
["in1", "in2", "in3"] ["out1"]
moore3SysF i1 i2 i3 =
mapSY "map" output $ scanld3SY "mooreScan" nextState initial i1 i2 i3
mealySY :: (ProcType a, ProcType b, ProcType c) =>
ProcId
-> ProcFun (a -> b -> a)
-> ProcFun (a -> b -> c)
-> a
-> Signal b
-> Signal c
mealySY id nextState output initial = instantiate id mealySys
where mealySys = newSysDef mealySysF ("mealySY_"++id) ["in1"] ["out1"]
mealySysF i = zipWithSY "zipWith" output state i
where state = scanldSY "scanld" nextState initial i
mealy2SY :: (ProcType a, ProcType b, ProcType c, ProcType d) =>
ProcId
-> ProcFun (a -> b -> c -> a)
-> ProcFun (a -> b -> c -> d)
-> a
-> Signal b
-> Signal c
-> Signal d
mealy2SY id nextState output initial = instantiate id mealy2Sys
where mealy2Sys = newSysDef mealy2SysF ("mealySY_"++id)
["in1", "in2"] ["out1"]
mealy2SysF i1 i2 = zipWith3SY "zipWith" output state i1 i2
where state = scanld2SY "scanld" nextState initial i1 i2
mealy3SY :: (ProcType a, ProcType b, ProcType c, ProcType d,
ProcType e) =>
ProcId
-> ProcFun (a -> b -> c -> d -> a)
-> ProcFun (a -> b -> c -> d -> e)
-> a
-> Signal b
-> Signal c
-> Signal d
-> Signal e
mealy3SY id nextState output initial = instantiate id mealy3Sys
where mealy3Sys = newSysDef mealy3SysF ("mealySY_"++id)
["in1", "in2", "in3"] ["out1"]
mealy3SysF i1 i2 i3 = zipWith4SY "zipWith" output state i1 i2 i3
where state = scanld3SY "scanld" nextState initial i1 i2 i3
filterSY :: ProcType a =>
ProcId
-> ProcFun (a -> Bool)
-> Signal a
-> Signal (AbstExt a)
filterSY id pred = mapSY id (filterer `defArgPF` pred)
where filterer =
$(newProcFun [d| filterer :: (a -> Bool) -> a -> AbstExt a
filterer pred val =
if pred val then Prst val
else Abst |])
sourceSY :: ProcType a =>
ProcId
-> ProcFun (a -> a)
-> a
-> Signal a
sourceSY id f s0 = instantiate id sourceSys
where sourceSys = newSysDef sourceSysF ("sourceSY_"++id)
[] ["out1"]
sourceSysF = o
where o = delaySY "delay" s0 s
s = mapSY "map" f o
fillSY :: ProcType a =>
ProcId
-> a
-> Signal (AbstExt a)
-> Signal a
fillSY id v s = mapSY id (replaceAbst `defArgVal` v) s
where replaceAbst :: ProcFun (a -> AbstExt a -> a)
replaceAbst = $(newProcFun
[d| replaceAbst :: a -> AbstExt a -> a
replaceAbst x y = fromAbstExt x y |])
holdSY :: ProcType a =>
ProcId
-> a
-> Signal (AbstExt a)
-> Signal a
holdSY id a s = scanlSY id hold a s
where hold = $(newProcFun [d| hold :: a -> AbstExt a -> a
hold a abs = fromAbstExt a abs |])
whenSY :: (ProcType a, ProcType b) =>
ProcId
-> Signal (AbstExt a) -> Signal (AbstExt b) -> Signal (AbstExt a)
whenSY id = zipWithSY id whenF
where whenF = $(newProcFun [d| whenF :: AbstExt a -> AbstExt b -> AbstExt a
whenF v1 v2 = if isAbsent v2
then Abst
else v1 |])
zipSY :: (ProcType a, ProcType b) =>
ProcId
-> Signal a
-> Signal b
-> Signal (a,b)
zipSY id = zipWithSY id tup2
where tup2 :: ProcFun (a -> b -> (a,b))
tup2 = $(newProcFun [d| tup2 :: a -> b -> (a,b)
tup2 a b = (a,b) |])
zip3SY :: (ProcType a, ProcType b, ProcType c) =>
ProcId ->
Signal a ->
Signal b ->
Signal c ->
Signal (a,b,c)
zip3SY id = zipWith3SY id tup3
where tup3 :: ProcFun (a -> b -> c -> (a,b,c))
tup3 = $(newProcFun [d| tup3 :: a -> b -> c -> (a,b,c)
tup3 a b c = (a,b,c) |])
zip4SY :: (ProcType a, ProcType b, ProcType c, ProcType d) =>
ProcId ->
Signal a ->
Signal b ->
Signal c ->
Signal d ->
Signal (a,b,c,d)
zip4SY id = zipWith4SY id tup4
where tup4 :: ProcFun (a -> b -> c -> d -> (a,b,c,d))
tup4 = $(newProcFun [d| tup4 :: a -> b -> c -> d -> (a,b,c,d)
tup4 a b c d = (a,b,c,d) |])
zip5SY :: (ProcType a, ProcType b, ProcType c, ProcType d, ProcType e) =>
ProcId ->
Signal a ->
Signal b ->
Signal c ->
Signal d ->
Signal e ->
Signal (a,b,c,d,e)
zip5SY id = zipWith5SY id tup5
where tup5 :: ProcFun (a -> b -> c -> d -> e -> (a,b,c,d,e))
tup5 = $(newProcFun [d| tup5 :: a -> b -> c -> d -> e -> (a,b,c,d,e)
tup5 a b c d e = (a,b,c,d,e) |])
zip6SY :: (ProcType a, ProcType b, ProcType c, ProcType d, ProcType e,
ProcType f) =>
ProcId ->
Signal a ->
Signal b ->
Signal c ->
Signal d ->
Signal e ->
Signal f ->
Signal (a,b,c,d,e,f)
zip6SY id = zipWith6SY id tup6
where tup6 :: ProcFun (a -> b -> c -> d -> e -> f -> (a,b,c,d,e,f))
tup6 = $(newProcFun [d| tup6 :: a -> b -> c -> d -> e -> f ->
(a,b,c,d,e,f)
tup6 a b c d e f = (a,b,c,d,e,f) |])
unzipSY :: forall a b . (ProcType a, ProcType b) =>
ProcId
-> Signal (a,b)
-> (Signal a,Signal b)
unzipSY id s = (Signal (newNodeOutSig nodeRef (UnzipNSYOut 1)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 2)))
where ts = [typeOf (undefined :: a), typeOf (undefined :: b)]
nodeRef = newURef $ Proc id $
UnzipNSY ts untup (unSignal s)
untup :: Dynamic -> [Dynamic]
untup i = let (t1,t2) = ((fromJust.fromDynamic) i) :: (a,b)
in [toDyn t1, toDyn t2]
unzip3SY :: forall a b c . (ProcType a, ProcType b, ProcType c) =>
ProcId
-> Signal (a,b,c)
-> (Signal a, Signal b, Signal c)
unzip3SY id s = (Signal (newNodeOutSig nodeRef (UnzipNSYOut 1)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 2)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 3)))
where ts = [typeOf (undefined :: a), typeOf (undefined :: b),
typeOf (undefined :: c)]
nodeRef = newURef $ Proc id $
UnzipNSY ts untup3 (unSignal s)
untup3 :: Dynamic -> [Dynamic]
untup3 i = let (t1,t2,t3) = ((fromJust.fromDynamic) i) :: (a,b,c)
in [toDyn t1, toDyn t2, toDyn t3]
unzip4SY :: forall a b c d . (ProcType a, ProcType b, ProcType c,
ProcType d) =>
ProcId
-> Signal (a,b,c,d)
-> (Signal a, Signal b, Signal c, Signal d)
unzip4SY id s = (Signal (newNodeOutSig nodeRef (UnzipNSYOut 1)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 2)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 3)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 4)))
where ts = [typeOf (undefined :: a), typeOf (undefined :: b),
typeOf (undefined :: c), typeOf (undefined :: d)]
nodeRef = newURef $ Proc id $
UnzipNSY ts untup4 (unSignal s)
untup4 :: Dynamic -> [Dynamic]
untup4 i = let (t1,t2,t3,t4) = ((fromJust.fromDynamic) i) :: (a,b,c,d)
in [toDyn t1, toDyn t2, toDyn t3, toDyn t4]
unzip5SY :: forall a b c d e . (ProcType a, ProcType b, ProcType c,
ProcType d, ProcType e) =>
ProcId
-> Signal (a,b,c,d,e)
-> (Signal a, Signal b, Signal c, Signal d, Signal e)
unzip5SY id s = (Signal (newNodeOutSig nodeRef (UnzipNSYOut 1)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 2)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 3)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 4)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 5)))
where ts = [typeOf (undefined :: a), typeOf (undefined :: b),
typeOf (undefined :: c), typeOf (undefined :: d),
typeOf (undefined :: e)]
nodeRef = newURef $ Proc id $
UnzipNSY ts untup5 (unSignal s)
untup5 :: Dynamic -> [Dynamic]
untup5 i = let (t1,t2,t3,t4,t5)
= ((fromJust.fromDynamic) i) :: (a,b,c,d,e)
in [toDyn t1, toDyn t2, toDyn t3, toDyn t4, toDyn t5]
unzip6SY :: forall a b c d e f . (ProcType a, ProcType b, ProcType c,
ProcType d, ProcType e, ProcType f) =>
ProcId
-> Signal (a,b,c,d,e,f)
-> (Signal a, Signal b, Signal c, Signal d, Signal e, Signal f)
unzip6SY id s = (Signal (newNodeOutSig nodeRef (UnzipNSYOut 1)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 2)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 3)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 4)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 5)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 6)))
where ts = [typeOf (undefined :: a), typeOf (undefined :: b),
typeOf (undefined :: c), typeOf (undefined :: d),
typeOf (undefined :: e), typeOf (undefined :: f)]
nodeRef = newURef $ Proc id $
UnzipNSY ts untup6 (unSignal s)
untup6 :: Dynamic -> [Dynamic]
untup6 i = let (t1,t2,t3,t4,t5,t6)
= ((fromJust.fromDynamic) i) :: (a,b,c,d,e,f)
in [toDyn t1, toDyn t2, toDyn t3, toDyn t4, toDyn t5,
toDyn t6]
zipxSY :: (Nat s, Typeable s, ProcType a) =>
ProcId
-> FSVec s (Signal a)
-> Signal (FSVec s a)
zipxSY id = zipWithxSY id vectId
where vectId = $(newProcFun [d| vectId :: FSVec s a -> FSVec s a
vectId v = v |])
unzipxSY :: forall s a . (Typeable s, Nat s, ProcType a) =>
ProcId
-> Signal (FSVec s a)
-> FSVec s (Signal a)
unzipxSY id vs = V.map (\tag -> Signal (newNodeOutSig nodeRef tag) )
(reallyUnsafeVector [UnzipxSYOut i | i <- [1..n]])
where n = toInt (undefined :: s)
t = typeOf (undefined :: a)
nodeRef = newURef $ Proc id $
UnzipxSY t n unvector (unSignal vs)
unvector :: Dynamic -> [Dynamic]
unvector i = let v = ((fromJust.fromDynamic) i) :: FSVec s a
in map toDyn (V.fromVector v)
fstSY :: (ProcType a, ProcType b) => ProcId -> Signal (a,b) -> Signal a
fstSY id = mapSY id first
where first = $(newProcFun [d| first :: (a,b) -> a
first (a,_) = a |])
sndSY :: (ProcType a, ProcType b) => ProcId -> Signal (a,b) -> Signal b
sndSY id = mapSY id second
where second = $(newProcFun [d| second :: (a,b) -> b
second (_,b) = b |])
groupSY :: forall k a . (Nat k, Typeable k, ProcType a) =>
ProcId -> k -> Signal a -> Signal (AbstExt (FSVec k a))
groupSY id k = mooreSY id (f `defArgVal` kV) (g `defArgVal` kV) s0
where
kV = toInt k
s0 = (0, V.copy k (undefined :: a))
f = $(newProcFun [d| f :: Nat k' => Int -> (Int, FSVec k' a') -> a' ->
(Int, FSVec k' a')
f k (count,v) a =
(count+1 `mod` k, unsafeReplace v count a) |])
g = $(newProcFun [d| g :: Nat k' => Int -> (Int, FSVec k' a') -> AbstExt (FSVec k' a')
g k (count,v) = if k1 == count then Prst v else Abst |])
unsafeReplace :: Nat s => FSVec s a' -> Int -> a' ->FSVec s a'
unsafeReplace v i a =
reallyUnsafeVector $ unsafeReplace' (fromVector v) i a
where unsafeReplace' [] _ _ = []
unsafeReplace' (_:xs) 0 y = (y:xs)
unsafeReplace' (x:xs) n y = x : (unsafeReplace' xs (n 1) y)