
15 Sep
2010
15 Sep
'10
5:40 p.m.
Chad Scherrer
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