
On Sun, Sep 25, 2011 at 10:05 PM, Ozgur Akgun
Hi.
On 25 September 2011 18:10, Brent Yorgey
wrote: You must at least agree that it is short.
Not trying to start language wars here, but it is not terribly short for what it does. The following code does the same thing in C#, and isn't far longer. And it has more or less a one-to-one correspondence to the given Haskell code; open a file for reading, open a file for writing, read some number of bytes, apply the transformation, write it to the output file. Flushing the input/output buffers and closing the files are handled by the using construct, similar to withFile in the Haskell example. int chunksize = 4096; using (var r = new BinaryReader(File.OpenRead("infile"))) using (var w = new BinaryWriter(File.OpenWrite("outfile"))) for (var buffer = r.ReadBytes(chunksize); buffer.Length > 0; buffer = r.ReadBytes(chunksize)) w.Write(Array.ConvertAll(buffer, p => (byte) ~p));
Note that this code is pretty close to FP already (except the "for" loop which is where the iteratees/enumerator that present the main difficulty in Haskell trying to do the FP equivalent intervene) : the "using" is pretty declarative, you use a closure and a higher order function... -- Jedaï