Enumeratees are killing me

I'm trying to write what I think should be a simple Enumeratee, but I'm just not having any luck getting it to typecheck, and I'm coming to the realization that I still have no idea what I'm doing. The essential thing I want to do is adapt Data.Enumerator.List.concatMapAccum so that the accumulator function has the type (s -> ao -> Either (ao, [ai]) (s, [ai]) ) . The accumulator returning Right (s, [ai]) behaves as normal, while returning Left (ao, [ai]) will cause the Enumeratee to call the upstream Iterator one last time with (Chunks ai) and then yield with the (ao : xs). I just can't make it work though. Here's the guts of my attempt: step _ k EOF = yield (Continue k) EOF step s k (Chunks xs) = loop s k xs loop s k [] = continue (step s k) loop s k (x:xs) = case decoder s x of Left (extra, ai) -> k (Chunks ai) >>== checkDone (\k' -> yield () $ Chunks (extra:xs)) Right (s', ai) -> k (Chunks ai) >>== checkDoneEx (Chunks xs) (\k' -> loop s' k' xs) At this point I've tried putting a bunch of random stuff into the part to the right of (>>==) in the Left case of loop, but without any luck. Any help would be much appreciated. It seems really weird to me that none of the built-in functions for Enumeratees let you stop before the Enumerator is done. That seems like a really common thing that a person would want; in my case, I'm parsing messages out of a byte stream, so I want to stop each Enumeratee as it finishes its message, but that doesn't seem possible without dropping down to this level.

Well, I got it working. It seems to behave sanely when put in a chain with other Enumeratee/Iteratee combinations, so I'm happy. My solution is posted on hpaste: http://hpaste.org/51430 . I'd love any criticism that anybody has, especially since it seems to me to be an ideal building block for the sorts of Enumeratees that I'm building.

I am waiting for a web service where I can enter the type I want to process,
the iterator package to use, and which will spit out the types and an
example.
Then life will be good.
Alexander
On 16 September 2011 22:46, tsuraan
Well, I got it working. It seems to behave sanely when put in a chain with other Enumeratee/Iteratee combinations, so I'm happy. My solution is posted on hpaste: http://hpaste.org/51430 . I'd love any criticism that anybody has, especially since it seems to me to be an ideal building block for the sorts of Enumeratees that I'm building.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (2)
-
Alexander Kjeldaas
-
tsuraan