Re: [Haskell-cafe] A probably-stupid question about a Prelude implementation.

2007-06-22 Thread Neil Mitchell
Hi Michael, You're wrong :) foldr (||) False (repeat True) Gives: True Remember that in Haskell everything is lazy, which means that the || short-circuits as soon as it can. Thanks Neil On 6/22/07, Michael T. Richter [EMAIL PROTECTED] wrote: So, I'm now going over the code in the

Re: [Haskell-cafe] A probably-stupid question about a Prelude implementation.

2007-06-22 Thread Philip Armstrong
On Fri, Jun 22, 2007 at 11:31:17PM +0800, Michael T. Richter wrote: 1. Using foldr means I'll be traversing the whole list no matter what. This implies (perhaps for a good reason) that it can only work on a finite list. foldr is lazy. Please tell me I'm wrong and that I'm

Re: [Haskell-cafe] A probably-stupid question about a Prelude implementation.

2007-06-22 Thread Dougal Stanton
On 22/06/07, Michael T. Richter [EMAIL PROTECTED] wrote: So, I'm now going over the code in the 'Report with a fine-toothed comb because a) I'm actually able to read it now pretty fluently and b) I want to know what's there in detail for a project I'm starting. I stumbled across this code:

Re: [Haskell-cafe] A probably-stupid question about a Prelude implementation.

2007-06-22 Thread Chris Kuklewicz
Neil Mitchell wrote: Hi Michael, You're wrong :) foldr (||) False (repeat True) Gives: True Remember that in Haskell everything is lazy, which means that the || short-circuits as soon as it can. Thanks Neil Specifically it is graph reduced like this: or [F,T,F,F...] foldr (||)

[Haskell-cafe] A probably-stupid question about a Prelude implementation.

2007-06-22 Thread Michael T. Richter
So, I'm now going over the code in the 'Report with a fine-toothed comb because a) I'm actually able to read it now pretty fluently and b) I want to know what's there in detail for a project I'm starting. I stumbled across this code: any :: (a - Bool) - [a] - Bool any p = or .

Re: [Haskell-cafe] A probably-stupid question about a Prelude implementation.

2007-06-22 Thread Dan Weston
This is how I think of it: lazyIntMult :: Int - Int - Int lazyIntMult 0 _ = 0 lazyIntMult _ 0 = 0 lazyIntMult a b = a * b *Q 0 * (5 `div` 0) *** Exception: divide by zero *Q 0 `lazyIntMult` (5 `div` 0) 0 foldr evaluates a `f` (b `f` (c `f` ...)) Only f knows which arguments are strict and in

Re: [Haskell-cafe] A probably-stupid question about a Prelude implementation.

2007-06-22 Thread Bulat Ziganshin
Hello Michael, Friday, June 22, 2007, 7:31:17 PM, you wrote: no surprise - you got a lot of answers :) it is the best part of Haskell, after all :) the secret Haskell weapon is lazy evaluation which makes *everything* short-circuited. just consider standard () definition: () False _ = False

Re: [Haskell-cafe] A probably-stupid question about a Prelude implementation.

2007-06-22 Thread Andrew Coppin
Chris Kuklewicz wrote: Specifically it is graph reduced like this: or [F,T,F,F...] foldr (||) F [F,T,F,F...] F || foldr (||) F [T,F,F...] foldr (||) F [T,F,F...] T || foldr (||) F [F,F...] T The last line is because (T || _ = T) and lazyness I must sheepishly confess that I mistakenly

Re: [Haskell-cafe] A probably-stupid question about a Prelude implementation.

2007-06-22 Thread Andrew Coppin
Bulat Ziganshin wrote: no surprise - you got a lot of answers :) it is the best part of Haskell, after all :) Only if you ask easy questions. ;-) the secret Haskell weapon is lazy evaluation which makes *everything* short-circuited. just consider standard () definition: Again, only

Re: [Haskell-cafe] A probably-stupid question about a Prelude implementation.

2007-06-22 Thread Jan-Willem Maessen
On Jun 22, 2007, at 2:30 PM, Dan Weston wrote: This is how I think of it: lazyIntMult :: Int - Int - Int lazyIntMult 0 _ = 0 lazyIntMult _ 0 = 0 lazyIntMult a b = a * b *Q 0 * (5 `div` 0) *** Exception: divide by zero *Q 0 `lazyIntMult` (5 `div` 0) 0 foldr evaluates a `f` (b `f` (c `f`

Re: [Haskell-cafe] A probably-stupid question about a Prelude implementation.

2007-06-22 Thread Michael T. Richter
On Fri, 2007-22-06 at 22:28 +0400, Bulat Ziganshin wrote: no surprise - you got a lot of answers :) it is the best part of Haskell, after all :) Yes, that is one of the best parts of Haskell. And I sometimes even understand the answers which is better! the secret Haskell weapon is lazy