On Tue, Feb 9, 2010 at 4:03 AM, Maciej Piechotka <span dir="ltr">&lt;<a href="mailto:uzytkownik2@gmail.com">uzytkownik2@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I read a lot about iteratee IO and it seemed very interesting<br>
(Unfortunately it lacks tutorial). Especially features like &#39;no input<br>
yet&#39; in network programming (with lazy IO + parsec I run into problems<br>
as it tried to evaluate the first response character before sending<br>
output).<br>
<br>
I decided first write a simple program and then attempt write a Stream<br>
implementation for parsec.<br>
<br>
&gt; {-# LANGUAGE FlexibleInstances #-}<br>
&gt; {-# LANGUAGE MultiParamTypeClasses #-}<br>
&gt; import Data.Iteratee<br>
&gt; import Text.Parse<br>
&gt;<br>
&gt; data Buffer a = Buffer<br>
&gt; instance Monad m =&gt; Stream (Buffer a) (IterateeG [] a m) a where<br>
&gt;     uncons Buffer = IterateeG loop<br>
&gt;                     where loop (Chunk [])     =<br>
&gt;                               return $! Cont (IterateeG loop) Nothing<br>
&gt;                           loop (Chunk (x:xs)) =<br>
&gt;                               return $! Done (Just (x, Buffer))<br>
&gt;                                              (Chunk xs)<br>
&gt;                           loop (EOF Nothing)  =<br>
&gt;                               return $! Done Nothing (EOF Nothing)<br>
&gt;                           loop (EOF (Just e)) =<br>
&gt;                               return $! throwErr e<br>
<br>
1. I&#39;m not quite sure what Cursor was suppose to do from A Parsing<br>
Trifecta presentation.<br></blockquote><div><br>Note that my parsing trifecta Iteratee differs from the iteratees defined by Oleg et al; it has access to the entire input so far (accumulated in a fingertree). The Cursor is the index into that finger tree, and is tracked as the &#39;remaining input&#39; by Parsec, allowing backtracking. The presentation up to that point centers on the changes necessary to Iteratee to make this possible. <br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
2. Is there any package which contains this stream definition?<br></blockquote><div><br>Not that I&#39;m aware of, but I hardly qualify as an expert in the mainline Iteratee implementation. <br></div><div><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

3. Why Seek FileOffset is error message?<br></blockquote><div><br>I&#39;m not quite sure what you&#39;re asking here.<br><br>-Edward Kmett<br></div></div>