On Friday, September 15, 2017 at 7:17:33 PM UTC+2, Gabriel Gonzalez wrote:
>
> Note that this applies to the type that you gave, too!  There is no way to 
> deduce from the type that the initial state won't be used to produce a 
> value :)
>


Ah, you're right, of course. The "done" function may emit stuff without any 
input. The problem is that if I remove it and go the Mealy machine route 
some ways of splitting seem to become impossible. For example, imagine 
splitting a text stream on a two-char separator (while removing the 
separator).
 

>
> However, looking at this more closely I'm not sure that your original type 
> for `delimit` is sufficiently general to handle most use cases for grouping 
> a stream.  If I'm reading the type correctly I think this assumes that you 
> have one group of `b`s per original `a` in the input stream, which might 
> not be the case.  For example, consider this function that groups a stream 
> of text chunks into lines:
>
>     lines :: Monad m => Stream (Of Text) m r -> Stream (Stream (Of Text)) 
> m r
>
> I don't see how you could implement that in terms of `delimit`
>
>
>
Instead of the step function returning  *NonEmpty b*, it should return 
*NonEmpty 
[b]:*

*delimit :: Monad m => (x -> a -> (x, NonEmpty [b])) -> (x -> NonEmpty [b]) 
-> x -> Stream a m r -> Groups b m r*


I think this covers the case in which we encounter multiple newlines in a 
single block of text. It would be like:

lines :: Stream T.Text IO r -> Groups T.Text IO r
lines =
    Y.delimit (\nl txt ->
                  if T.null txt
                     then (nl,pure [])
                     else let nl' = T.last txt == '\n'
                          in case (nl,T.lines txt) of
                              (True,ls)    -> (nl', []  :| map pure ls)
                              (False,l:ls) -> (nl', [l] :| map pure ls)
                              (_,[])       -> error "never happens")
              (\_ -> pure [])
              True

 

-- 
You received this message because you are subscribed to the Google Groups 
"Haskell Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to haskell-pipes+unsubscr...@googlegroups.com.
To post to this group, send email to haskell-pipes@googlegroups.com.

Reply via email to