Say I have this code:
import Control.Monad.State hiding (StateT)
import Control.Proxy
server :: (Proxy p, Monad m) => Int -> Server p Int Bool (StateT Int m) ()
server = runIdentityK loop
where loop arg = do
currMax <- lift get
lift $ put $ max currMax arg
nextArg <- respond (even arg)
loop nextArg
client :: (Proxy p, Monad m) => Client p Int Bool m ()
client = runIdentityP loop
where loop = go 1
go i = do
isEven <- request i
go $ if isEven
then i `div` 2
else i * 3 + 1
Currently the client always sends Int
, and receives Bool
. However, I want the client to also be able to query for the highest value that the server has seen so far. So I also need communication of sending ()
and receiving Int
. I could encode this as the client sending Either Int ()
, and receiving Either Bool Int
. However, I'd like to ensure that the two aren't mixed - sending an Int
always gets a Bool
response.
How can this be done?