You need to use foreverK instead of forever , for example:
module Toy where import Pipes import Pipes.Prelude (foreverK) import Control.Monad.State type Request = String type Response = String serveChoice :: Request -> Server Request Response IO () serveChoice = foreverK go where go req = do lift $ putStrLn req respond req run :: Monad m => () -> Client Request Response (StateT Int m) () run () = do request "hi" return () main :: IO () main = evalStateT (runEffect $ hoist lift . serveChoice >-> run $ ()) 0
The reason your original version freezes is because you used forever in the Reader monad (i.e. in the monad ((->) a) ), and not in the monad. Inside this monad, forever equivalent to ⊥ :
foreverK is probably what you wanted as it is the same idiom for Server presented in the pipes-3.3.0 tutorial.
This change fixes a program that has now completed normally:
>>> main hi >>>
Gabriel gonzalez
source share