[Haskell-beginners] how more efficient read/write a file ?

David McBride toad3k at gmail.com
Sun Sep 25 01:30:20 CEST 2011


If you wanted to use enumerator, it isn't too tough.  You would do
something like this:

import Data.Enumerator (run_, ($$), (=$))
import Data.Enumerator.Binary (enumHandle, iterHandle)
import Data.Enumerator.List as EL (map)

import Data.ByteString as B (map)
import Data.Bits (complement)
import System.IO (withFile, IOMode(..))

main = withFile "infile" ReadMode $ \inh -> withFile "outfile"
WriteMode $ \outh -> do
  run_ (enumHandle 4096 inh $$ EL.map (B.map complement) =$ iterHandle outh)


On Sat, Sep 24, 2011 at 2:00 PM, Kyle Murphy <orclev at gmail.com> wrote:
> It's not for the faint of heart, but the enumerator package is also supposed
> to provide very good performance for stream transformations. I've looked at
> it a bit myself but I'm still struggling to wrap my head around the types
> involved, which like most things in Haskell is the key to understanding the
> whole thing.
>
> -R. Kyle Murphy
> --
> Curiosity was framed, Ignorance killed the cat.
>
>
> On Sat, Sep 24, 2011 at 05:01, Benjamin Edwards <edwards.benj at gmail.com>
> wrote:
>>
>> You should look up bytestring and friends on hackage.
>>
>> If it is something quite simple you can use the lazy variants and provided
>> that you don't try to hold onto the input you should get nice constant space
>> without trying too hard.
>>
>> I recommend the early chapters on IO in real world haskell if you want
>> more info on lazy IO.
>>
>> On 24 Sep 2011 03:06, "anyzhen" <jiangzhen3s at qq.com> wrote:
>> > consider this :
>> > i want load a 4G file(or some bigger file) ,and the process data
>> > operation just like 010 to 101( XOR bits ) , is it some efficient function
>> > down it ?
>> > such hPutStr hPutChar is Char layer , is exist bit layer operations?
>> >
>> >
>> > thanks for any help
>> >
>> >
>> > jiangzhen3s at qq.com
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>



More information about the Beginners mailing list