我正在尝试从由 WriterT 包装的 IO 生成无限的惰性值流。我正在使用管道来使用此流并将其写入文件。我很清楚 IO 在其绑定运算符中的严格性,那么我怎么能在其中懒惰地产生这个流 IO 呢?
如果不可能,我是不是应该尝试换成懒惰的ST?
import Data.Conduit
import Control.Monad.Writer
import Data.DList as DL
type Stream = WriterT (DL.DList String) IO ()
generator :: Stream
generator = do
tell $ DL.singleton "something"
generator
runStream :: Stream -> IO ()
runStream s = runResourceT $ stream s
where stream s = sourceStream s $$ sinkStream -- sinkStream just writes to a file
sourceStream s = do w <- liftIO $ execWriterT s
CL.sourceList (DL.toList w)