Re: [Haskell-cafe] hash of a lazy bytestring?

2007-05-13 Thread David Roundy
On Sun, May 13, 2007 at 08:30:41AM -0700, David Roundy wrote:
 do l - readFile foo
let len = length l
writeFile bar l
putStrLn $ Length is  ++ show l

Oops, of course this should have been show len in the last line.
-- 
David Roundy
http://www.darcs.net
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] hash of a lazy bytestring?

2007-05-13 Thread Tom Schrijvers

On Sun, 13 May 2007, David Roundy wrote:


I was just contemplating hashes, and it occurred to me that it would be
nice to be able to compute the hash of a lazily constructed bytestring and
lazily consume its output without requiring the whole string to ever be in
memory.  Or in general, it'd be nice to be able to perform two simultaneous
consumptions of a lazy list without requiring that the entire list be
stored.


How about reading the same file twice?

do l1 - readFile foo
   l2 - readFile foo
   let len = length l1
   writeFile bar l2
   ...
Another solution would be loop fusion:

do l - readFile foo
   len - writeFileAndComputeLength bar l
   ...

A compiler might be able to do that for you.

Tom

--
Tom Schrijvers

Department of Computer Science
K.U. Leuven
Celestijnenlaan 200A
B-3001 Heverlee
Belgium

tel: +32 16 327544
e-mail: [EMAIL PROTECTED]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] hash of a lazy bytestring?

2007-05-13 Thread Henning Thielemann

On Sun, 13 May 2007, David Roundy wrote:

 I was just contemplating hashes, and it occurred to me that it would be
 nice to be able to compute the hash of a lazily constructed bytestring and
 lazily consume its output without requiring the whole string to ever be in
 memory.  Or in general, it'd be nice to be able to perform two simultaneous
 consumptions of a lazy list without requiring that the entire list be
 stored.  Another example would be computing the length of an ordinary list:

 do l - readFile foo
let len = length l
writeFile bar l
putStrLn $ Length is  ++ show l

An elegant implementation of 'wc' is another example.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe