On Tue, Feb 9, 2010 at 4:03 AM, Maciej Piechotka <uzytkownik2@gmail.com> wrote:
I read a lot about iteratee IO and it seemed very interesting
(Unfortunately it lacks tutorial). Especially features like 'no input
yet' in network programming (with lazy IO + parsec I run into problems
as it tried to evaluate the first response character before sending
output).
I decided first write a simple program and then attempt write a Stream
implementation for parsec.
> {-# LANGUAGE FlexibleInstances #-}
> {-# LANGUAGE MultiParamTypeClasses #-}
> import Data.Iteratee
> import Text.Parse
>
> data Buffer a = Buffer
> instance Monad m => Stream (Buffer a) (IterateeG [] a m) a where
> uncons Buffer = IterateeG loop
> where loop (Chunk []) =
> return $! Cont (IterateeG loop) Nothing
> loop (Chunk (x:xs)) =
> return $! Done (Just (x, Buffer))
> (Chunk xs)
> loop (EOF Nothing) =
> return $! Done Nothing (EOF Nothing)
> loop (EOF (Just e)) =
> return $! throwErr e
1. I'm not quite sure what Cursor was suppose to do from A Parsing
Trifecta presentation.
2. Is there any package which contains this stream definition?
3. Why Seek FileOffset is error message?