[Haskell-cafe] [iteratee] how to do nothing .. properly
Sergey Mironov
ierton at gmail.com
Thu Jun 2 11:02:58 CEST 2011
Ok. I've checked iteratee-0.8.3.0 and 0.8.4.0. Results are same.
Sergey
2011/6/2 John Lato <jwlato at gmail.com>:
> Hi Sergey,
> I can't explain this; maybe it's a bug in enumWith? I'll look into it.
> Thanks,
> John
>
>>
>> Message: 20
>>
>> Date: Thu, 2 Jun 2011 02:46:32 +0400
>> From: Sergey Mironov <ierton at gmail.com>
>> Subject: [Haskell-cafe] [iteratee] how to do nothing .. properly
>> To: haskell-cafe at haskell.org
>> Message-ID: <BANLkTimMFRWgH9Nopt-eua+L7jQcGq+u=g at mail.gmail.com>
>> Content-Type: text/plain; charset=ISO-8859-1
>>
>> Hi. Would anybody explain a situation with iter6 and iter7 below?
>> Strange thing - first one consumes no intput, while second consumes it
>> all, while all the difference is peek which should do no processing
>> (just copy next item in stream and return to user).
>> What I am trying to do - is to write an iteratee consuing no input,
>> but returning a constant I give to it. I thought (return a) should do
>> it, but it seems I was wrong as return actually consumes all unparsed
>> stream. iter6 experience tells me that (peek>>return a) is what I
>> need, but it's completely confusing and not what I expected.
>>
>> Thanks,
>> Sergey
>>
>> import Data.Iteratee as I
>> import Data.Iteratee.IO
>> import Control.Monad
>> import Control.Exception
>> import Data.ByteString
>> import Data.Char
>> import Data.String
>>
>> -- countBytes :: (..., Num b) => Iteratee s m a -> Iteratee s m (a, b)
>> countBytes i = enumWith i I.length
>>
>> iter6 = do
>> h <- countBytes $ (peek >> return 0)
>> s <- I.stream2list
>> return (h,s)
>>
>> iter7 = do
>> h <- countBytes $ (return 0)
>> s <- I.stream2list
>> return (h,s)
>>
>> print6 = enumPure1Chunk [1..10] (iter6) >>= run >>= print
>> print7 = enumPure1Chunk [1..10] (iter7) >>= run >>= print
>>
>>
>> Here is example ghci session
>>
>> *Main> print6
>> ((0,0),[1,2,3,4,5,6,7,8,9,10])
>> -- read 0 items, returns 0
>> *Main> print7
>> ((0,10),[])
>> -- read 10 items (???) returns 0
>> *Main>
>>
>>
>>
>> ------------------------------
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>> End of Haskell-Cafe Digest, Vol 94, Issue 3
>> *******************************************
>
>
More information about the Haskell-Cafe
mailing list