module LoopLow(loopLow,loopThroughLowSP,loopThroughLowF) where
import CompSP
import Fudget
import Loop
import Loopthrough(loopThroughRightSP)
loopLow :: (SP TCommand (FCommand a)) -> (SP (FEvent a) TEvent) -> (F b c) -> F b c
loopLow :: forall a b c.
SP TCommand (FCommand a) -> SP (FEvent a) TEvent -> F b c -> F b c
loopLow SP TCommand (FCommand a)
ch SP (FEvent a) TEvent
eh (F FSP b c
f) =
let prep :: Either b (Message a b) -> Message (Message a b) b
prep (Left b
msg) = forall a b. a -> Message a b
Low (forall a b. b -> Message a b
High b
msg)
prep (Right (High b
msg)) = forall a b. b -> Message a b
High b
msg
prep (Right (Low a
msg)) = forall a b. a -> Message a b
Low (forall a b. a -> Message a b
Low a
msg)
post :: Message (Message a a) b -> Either a (Message a b)
post (High b
msg) = forall a b. b -> Either a b
Right (forall a b. b -> Message a b
High b
msg)
post (Low (High a
msg)) = forall a b. a -> Either a b
Left a
msg
post (Low (Low a
msg)) = forall a b. b -> Either a b
Right (forall a b. a -> Message a b
Low a
msg)
in forall hi ho. FSP hi ho -> F hi ho
F forall a b. (a -> b) -> a -> b
$
forall {a} {b1} {b2}. SP (Either a b1) (Either a b2) -> SP b1 b2
loopLeftSP
(forall {t1} {a} {t2} {b}.
(t1 -> a) -> (t2 -> b) -> SP a t2 -> SP t1 b
prepostMapSP forall {b} {a} {b}.
Either b (Message a b) -> Message (Message a b) b
prep forall {a} {a} {b}.
Message (Message a a) b -> Either a (Message a b)
post
(forall {a1} {a2} {b}. SP a1 a2 -> SP (Message a1 b) (Message a2 b)
idHighSP SP TCommand (FCommand a)
ch forall {a1} {b} {a2}. SP a1 b -> SP a2 a1 -> SP a2 b
`serCompSP` FSP b c
f forall {a1} {b} {a2}. SP a1 b -> SP a2 a1 -> SP a2 b
`serCompSP` forall {a1} {a2} {b}. SP a1 a2 -> SP (Message a1 b) (Message a2 b)
idHighSP SP (FEvent a) TEvent
eh))
loopThroughLowSP :: SP (Either c e) (Either c e) ->
SP (Message e a) (Message c b) ->
SP (Message e a) (Message c b)
loopThroughLowSP :: forall c e a b.
SP (Either c e) (Either c e)
-> SP (Message e a) (Message c b) -> SP (Message e a) (Message c b)
loopThroughLowSP SP (Either c e) (Either c e)
ctrl SP (Message e a) (Message c b)
f =
forall {a1} {b1} {a2} {b2}.
SP (Either a1 b1) (Either a2 b2) -> SP a2 a1 -> SP b1 b2
loopThroughRightSP (forall {t1} {a} {t2} {b}.
(t1 -> a) -> (t2 -> b) -> SP a t2 -> SP t1 b
prepostMapSP forall {a} {b} {b} {a}.
Either (Message a b) (Message b a)
-> Message (Either a b) (Either a b)
prep forall {a} {a} {b} {b}.
Message (Either a a) (Either b b)
-> Either (Message a b) (Message a b)
post (forall {a1} {a2} {b}. SP a1 a2 -> SP (Message a1 b) (Message a2 b)
idHighSP SP (Either c e) (Either c e)
ctrl)) SP (Message e a) (Message c b)
f
where
prep :: Either (Message a b) (Message b a)
-> Message (Either a b) (Either a b)
prep Either (Message a b) (Message b a)
msg = case Either (Message a b) (Message b a)
msg of
Right (High a
a) -> forall a b. b -> Message a b
High (forall a b. a -> Either a b
Left a
a)
Left (High b
a) -> forall a b. b -> Message a b
High (forall a b. b -> Either a b
Right b
a)
Right (Low b
e) -> forall a b. a -> Message a b
Low (forall a b. b -> Either a b
Right b
e)
Left (Low a
c) -> forall a b. a -> Message a b
Low (forall a b. a -> Either a b
Left a
c)
post :: Message (Either a a) (Either b b)
-> Either (Message a b) (Message a b)
post Message (Either a a) (Either b b)
msg = case Message (Either a a) (Either b b)
msg of
High (Left b
msg) -> forall a b. a -> Either a b
Left (forall a b. b -> Message a b
High b
msg)
High (Right b
msg) -> forall a b. b -> Either a b
Right (forall a b. b -> Message a b
High b
msg)
Low (Left a
c) -> forall a b. b -> Either a b
Right (forall a b. a -> Message a b
Low a
c)
Low (Right a
e) -> forall a b. a -> Either a b
Left (forall a b. a -> Message a b
Low a
e)
loopThroughLowF
:: SP (Either TCommand TEvent) (Either TCommand TEvent) -> F i o -> F i o
loopThroughLowF :: forall i o.
SP (Either TCommand TEvent) (Either TCommand TEvent)
-> F i o -> F i o
loopThroughLowF SP (Either TCommand TEvent) (Either TCommand TEvent)
ctrlSP (F FSP i o
fudSP) = forall hi ho. FSP hi ho -> F hi ho
F forall a b. (a -> b) -> a -> b
$ forall c e a b.
SP (Either c e) (Either c e)
-> SP (Message e a) (Message c b) -> SP (Message e a) (Message c b)
loopThroughLowSP SP (Either TCommand TEvent) (Either TCommand TEvent)
ctrlSP FSP i o
fudSP