Running the base monad of a pipe

haskell, pipe

Solution

Does it have to be `execStateT` ? It can be done easier with `runStateP` from `Pipes.Lift`.

import Pipes
import Pipes.Lift
import Control.Monad.State.Strict

-- unnecessarily specific signature, function work with any Proxy
foo :: Monad m => b -> Consumer a (StateT b m) () -> Consumer a m b
foo b p = liftM snd $ runStateP b p

The functions in `Pipes.Lift` are great when you have a pipeline for which different stages have different effects. It's better to limit an effect to the specific stage of the pipeline on which is needed.

Problem

Having the following stateful consumer: ``` consumer1 :: Consumer a (StateT b m) () ``` What is the optimal way to convert it to the following one with the help of `execStateT`? ``` consumer2 :: Consumer a m b ```

Original source