[Haskell-cafe] Re: Channel9 Interview: Software Composability and
the Future of Languages
apfelmus at quantentunnel.de
apfelmus at quantentunnel.de
Wed Jan 31 14:38:00 EST 2007
Bulat Ziganshin wrote:
>>> there are also many other similar issues, such as lack of good syntax
>>> for "for", "while", "break" and other well-known statements,
>
>> On the other hand you have an ability to define your own control
>> structures.
>
> i have a lot, but their features are limited, both in terms of
> automatic lifting and overall syntax. let's consider
>
> while (hGetBuf h buf bufsize == bufsize)
> crc := updateCrc crc buf bufsize
> break if crc==0
> print crc
I guess that the crc is a simple fold over the single bytes:
crc xs = foldl' (\crc word8 -> crc `xor` word8) 0 xs
You do not need xs to be an inefficient String, Data.ByteString.Lazy
gives you single byte access (f.i. via fold) but internally reads stuff
in a chunked way, just like you now manually do with hGetBuf. Lazy
evaluation is very handy for separating those the two concerns of
reading the chunks of bytes and presenting them in a non-chunked way.
Regards,
apfelmus
More information about the Haskell-Cafe
mailing list