[Haskell-beginners] clarity and complexity of Haskell code?

David McBride toad3k at gmail.com
Mon Sep 26 10:28:42 CEST 2011


As the guy that wrote that original snippet, II could always have done
this in an imperative style using lazy IO and it would have been
clearer.  But this way is just superior in terms of resources and
extensibility.  Someone wanted to know what the best way to do this in
haskell is and I think that is it.  This is no different than using a
library in another language.

I will admit it took me awhile to learn how to use enumerator.  But
once I did I found it to be an absolutely amazing way to think about
many common problems that I do.  What I like about it is that in this
case, I only needed to do one thing to the data.  This took me about 2
minutes to write and it worked on the first try.  If there were an
database system that used the enumerator library, I would be able to
do much of my daily workload in haskell.

Do I wish the enumerator library would be a little easier to use?  Yes
I do.  Is that even possible?  I don't know.

On Sun, Sep 25, 2011 at 5:07 PM,  <caseyh at istar.ca> wrote:
> Haskell is designed for heavy computational lifting; your example is not an
> example of major computational power.
>
> So, of course, Haskell code will not be short in ALL cases. :)
>
>
> Quoting Ozgur Akgun <ozgurakgun at gmail.com>:
>
>> Hi.
>>
>> On 25 September 2011 18:10, Brent Yorgey <byorgey at seas.upenn.edu> 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));
>>
>> I think the habit of using quite a few operators in Haskell does make the
>> learning curve steeper.
>>
>> I am not trying to say that the C# code is *better. *Just that the Haskell
>> code is not terribly short in this case and it can be a bit cryptic for a
>> newbie.
>>
>> Best,
>> Ozgur
>>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



More information about the Beginners mailing list