[Haskell-cafe] Re: IO Put confusion
Chad Scherrer
chad.scherrer at gmail.com
Wed Sep 15 17:40:27 EDT 2010
Chad Scherrer <chad.scherrer <at> gmail.com> writes:
> Second attempt:
> doc :: IO Put
> doc = docLength >>= go
> where
> go 1 = word
> go n = do
> w <- word
> ws <- go (n-1)
> return (w >> putSpace >> ws)
>
> This one actually works, but it holds onto everything in memory
> instead of outputting as it goes. If docLength tends to be large, this
> leads to big problems.
Sorry to answer my own post, but I've got a kludgy work-around now. I tried a
WriterT approach, and also building my own "PutT" like Data.Binary.Put, neither
with any luck. Instead I just changed the type to
word, doc :: IO ()
and had it write standard out as is goes. Not nearly as elegant, but at least it
works now.
Thanks,
Chad
More information about the Haskell-Cafe
mailing list