module NullF(module NullF, Cont(..),K,F,StreamProcIO(..),FudgetIO(..)) where
import Utils(pair)
import Fudget
import Message(aLow,stripHigh) --Message(..),
import Path(here)
import Spops
import Cont(dropSP,kContWrap,fContWrap,waitForK,waitForFu)
import StreamProcIO
import FudgetIO

--{- -}
instance StreamProcIO F where
  put :: forall o i. o -> F i o -> F i o
put = forall o i. o -> F i o -> F i o
putF
  get :: forall i o. (i -> F i o) -> F i o
get = forall i o. (i -> F i o) -> F i o
getF -- Discards low level input! Leave undefined?
  end :: forall i o. F i o
end = forall i o. F i o
nullF

instance StreamProcIO K where
  put :: forall o i. o -> K i o -> K i o
put = forall {f :: * -> * -> *} {ho} {hi}.
FudgetIO f =>
ho -> f hi ho -> f hi ho
putHigh
  get :: forall i o. (i -> K i o) -> K i o
get = forall {f :: * -> * -> *} {ans} {ho}.
FudgetIO f =>
(ans -> f ans ho) -> f ans ho
getHigh
  end :: forall i o. K i o
end = forall i o. K i o
nullK

instance FudgetIO F where
  waitForMsg :: forall hi ans ho. (KEvent hi -> Maybe ans) -> Cont (F hi ho) ans
waitForMsg = forall hi ans ho. (KEvent hi -> Maybe ans) -> Cont (F hi ho) ans
waitForFu
  putMsg :: forall ho hi. KCommand ho -> F hi ho -> F hi ho
putMsg = forall ho hi. KCommand ho -> F hi ho -> F hi ho
putMessageFu
  --nullMsg = nullF
  --getMsg = getMessageFu


instance FudgetIO K where
  putMsg :: forall ho hi. KCommand ho -> K hi ho -> K hi ho
putMsg = forall ho hi. KCommand ho -> K hi ho -> K hi ho
putK
  waitForMsg :: forall hi ans ho. (KEvent hi -> Maybe ans) -> Cont (K hi ho) ans
waitForMsg = forall hi ans ho. (KEvent hi -> Maybe ans) -> Cont (K hi ho) ans
waitForK
  --nullMsg = nullK
  --getMsg = getK

---}

----

nullK :: K hi ho
nullK = forall hi ho. KSP hi ho -> K hi ho
K{-kk-} forall a b. SP a b
nullSP
nullF :: F hi ho
nullF = forall hi ho. FSP hi ho -> F hi ho
F{-ff-} forall a b. SP a b
nullSP

--putK :: KCommand ho -> K hi ho -> K hi ho
putK :: KCommand ho -> K hi ho -> K hi ho
putK KCommand ho
o (K KSP hi ho
sp) = forall hi ho. KSP hi ho -> K hi ho
kk (forall b a. b -> SP a b -> SP a b
putSP KCommand ho
o KSP hi ho
sp)

putF :: ho -> F hi ho -> F hi ho
putF = forall {ho} {hi}. FCommand ho -> F hi ho -> F hi ho
putMessageF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. b -> Message a b
High

putsF :: [b] -> F a b -> F a b
putsF = forall {t :: * -> *} {sp :: * -> * -> *} {a} {i}.
(Foldable t, StreamProcIO sp) =>
t a -> sp i a -> sp i a
puts :: ([b] -> F a b -> F a b)
--putsF his f = foldr putF f his
putsK :: [KCommand b] -> K a b -> K a b
putsK = forall {t :: * -> *} {f :: * -> * -> *} {ho} {hi}.
(Foldable t, FudgetIO f) =>
t (KCommand ho) -> f hi ho -> f hi ho
putMsgs :: ([KCommand b] -> K a b -> K a b)
--putsK msgs k = foldr putK k msgs

putMessageF :: FCommand ho -> F hi ho -> F hi ho
putMessageF FCommand ho
msg (F FSP hi ho
sp) = forall hi ho. FSP hi ho -> F hi ho
F{-ff-} (forall b a. b -> SP a b -> SP a b
putSP FCommand ho
msg FSP hi ho
sp)
putMessageFu :: Message FRequest ho -> F hi ho -> F hi ho
putMessageFu = forall {ho} {hi}. FCommand ho -> F hi ho -> F hi ho
putMessageF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {t} {a} {b}. (t -> a) -> Message t b -> Message a b
aLow (forall {a} {b}. a -> b -> (a, b)
pair Path
here)

putMessagesF :: [FCommand ho] -> F hi ho -> F hi ho
putMessagesF [FCommand ho]
hos (F FSP hi ho
sp) = forall hi ho. FSP hi ho -> F hi ho
F{-ff-} (forall b a. [b] -> SP a b -> SP a b
putsSP [FCommand ho]
hos FSP hi ho
sp)
putMessagesFu :: [KCommand b] -> F a b -> F a b
putMessagesFu = forall {t :: * -> *} {f :: * -> * -> *} {ho} {hi}.
(Foldable t, FudgetIO f) =>
t (KCommand ho) -> f hi ho -> f hi ho
putMsgs :: ([KCommand b] -> F a b -> F a b)
--putMessagesFu msgs f = foldr putMessageFu f msgs

--appendStartK :: [KCommand b] -> K a b -> K a b
appendStartK :: [KCommand ho] -> K hi ho -> K hi ho
appendStartK [KCommand ho]
kcmds (K KSP hi ho
sp) = forall hi ho. KSP hi ho -> K hi ho
kk (forall b a. [b] -> SP a b -> SP a b
appendStartSP [KCommand ho]
kcmds KSP hi ho
sp)

--appendStartMessageF :: [FCommand b] -> F a b -> F a b
appendStartMessageF :: [FCommand ho] -> F hi ho -> F hi ho
appendStartMessageF [FCommand ho]
fcmds (F FSP hi ho
sp) = forall hi ho. FSP hi ho -> F hi ho
F{-ff-} (forall b a. [b] -> SP a b -> SP a b
appendStartSP [FCommand ho]
fcmds FSP hi ho
sp)

--appendStartF :: [b] -> F a b -> F a b
appendStartF :: [ho] -> F hi ho -> F hi ho
appendStartF = forall {ho} {hi}. [FCommand ho] -> F hi ho -> F hi ho
appendStartMessageF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall a b. b -> Message a b
High

getK :: Cont (K hi ho) (KEvent hi)
getK = forall hi ho a. Cont (KSP hi ho) a -> Cont (K hi ho) a
kContWrap forall a b. Cont (SP a b) a
getSP -- :: (Cont (K a b) (KEvent a))

getMessageF :: Cont (F hi ho) (FEvent hi)
getMessageF = forall hi ho a. Cont (FSP hi ho) a -> Cont (F hi ho) a
fContWrap forall a b. Cont (SP a b) a
getSP -- :: (Cont (F a b) (FEvent a))
getMessageFu :: Cont (F a b) (KEvent a)
getMessageFu = forall hi ho a. Cont (FSP hi ho) a -> Cont (F hi ho) a
fContWrap (forall a b. Cont (SP a b) a
getSP forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {t} {a} {b}. (t -> a) -> Message t b -> Message a b
aLow forall a b. (a, b) -> b
snd)) :: (Cont (F a b) (KEvent a))

--getF :: Cont (F a b) a
getF :: Cont (F a ho) a
getF = forall hi ho a. Cont (FSP hi ho) a -> Cont (F hi ho) a
fContWrap (forall {t1} {t2} {b}.
(t1 -> Maybe t2) -> (t2 -> SP t1 b) -> SP t1 b
dropSP forall {a1} {a2}. Message a1 a2 -> Maybe a2
stripHigh)

--startupK :: ([KEvent a] -> K a b -> K a b)
startupK :: [KEvent hi] -> K hi ho -> K hi ho
startupK [KEvent hi]
kevs (K KSP hi ho
sp) = forall hi ho. KSP hi ho -> K hi ho
kk (forall a b. [a] -> SP a b -> SP a b
startupSP [KEvent hi]
kevs KSP hi ho
sp)
--startupMessageF :: ([FEvent a] -> F a b -> F a b)
startupMessageF :: [FEvent hi] -> F hi ho -> F hi ho
startupMessageF [FEvent hi]
fevs (F FSP hi ho
sp) = forall hi ho. FSP hi ho -> F hi ho
F{-ff-} (forall a b. [a] -> SP a b -> SP a b
startupSP [FEvent hi]
fevs FSP hi ho
sp)

--startupMessageFu = startupMessageF . map (aLow (pair here)) -- error prone

--startupF :: [a] -> F a b -> F a b
startupF :: [hi] -> F hi ho -> F hi ho
startupF = forall {hi} {ho}. [FEvent hi] -> F hi ho -> F hi ho
startupMessageF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall a b. b -> Message a b
High

--delayF :: (F a b -> F a b)
delayF :: F hi ho -> F hi ho
delayF (F FSP hi ho
sp) = forall hi ho. FSP hi ho -> F hi ho
F{-ff-} (forall {a} {b}. SP a b -> SP a b
delaySP FSP hi ho
sp)