On 13/03/10 10:06, Juraj Hercek wrote:
Hello,
I'm thinking about using Data.Binary to parse binary stream of data.
Binary data stream consists of messages which can have one or more
(sometimes couple of hundreds) sub-messages. The stream is spitting
out data slowly.
I would like to parse this data with Data.Binary.Get monad, but I
would like to send sub-messages to a STM channel while parsing, so
"observers" could handle them during parsing process.
I think you could do this by having your top-level Get action return a
list of IO actions, like this:
bigGet :: Get ([IO ()])
Then arrange for the parser for each smaller sub-message to return the
corresponding action. In this case these actions will be calls to
"atomic" to run the appropriate STM action.
The trick is in lazyness: the lazy bytestring is read as it comes in,
and hence is translated to a lazy list of IO actions, which are also
executed as they come in.
Hope this helps,
Paul.
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe