[Haskell-cafe] Data.Binary.GetT or ... ?

Juraj Hercek juhe_haskell at hck.sk
Sun Mar 14 06:19:07 EDT 2010


On 03/13/2010 12:35 PM, Paul Johnson wrote:
> 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.

That's neat idea. I'll try it and see how it behaves.

Thanks,
Juraj


More information about the Haskell-Cafe mailing list