Re: [Haskell-cafe] Re: Wikipedia on first-class object

Right, so when I say to GHCi: Prelude> take 5 [1..] and it says: [1,2,3,4,5] then it really has computed the entirety of the infinite sequence [1..], and not some approximation?
Of course not! In fact, it doesn't even compute the value "1". It just juggles with the bytes somehow, so that it seems that it computes the whole sequence and then applies "take 5". But does it really matter if it computes 5 integers, or 10, or the whole sequence, at least if we are not concerned about performance?
Perhaps it is better to say that in a lazy language both approximations and maximal values (least upper bounds of a chain) are interesting.
Well, that depends of your notion of interesting.

On 28/12/2007, at 5:50 PM, Miguel Mitrofanov wrote:
Right, so when I say to GHCi:
Prelude> take 5 [1..]
and it says:
[1,2,3,4,5]
then it really has computed the entirety of the infinite sequence
[1..], and not some approximation?
Of course not! In fact, it doesn't even compute the value "1". It just juggles with the bytes somehow, so that it seems that it computes the whole sequence and then applies "take 5". But does it really matter if it computes 5 integers, or 10, or the whole sequence, at least if we are not concerned about performance?
I'll bite. So what do you expect: take 5 [1,2,3,4,5,undefined] to do? How about: take 5 (1:2:3:4:undefined) ? So it does seem to matter how much of the list it evaluates...
Perhaps it is better to say that in a lazy language both approximations and maximal values (least upper bounds of a chain) are interesting.
Well, that depends of your notion of interesting.
I defined it - I'm interested in things that are observationally equivalent. Please read the generalised-take-lemma paper. It will clear up some of this confusion. cheers peter

Peter Gammie wrote:
On 28/12/2007, at 5:50 PM, Miguel Mitrofanov wrote:
Right, so when I say to GHCi:
Prelude> take 5 [1..]
and it says:
[1,2,3,4,5]
then it really has computed the entirety of the infinite sequence
[1..], and not some approximation?
Of course not! In fact, it doesn't even compute the value "1". It just juggles with the bytes somehow, so that it seems that it computes the whole sequence and then applies "take 5". But does it really matter if it computes 5 integers, or 10, or the whole sequence, at least if we are not concerned about performance?
I'll bite. So what do you expect:
take 5 [1,2,3,4,5,undefined]
to do? How about:
take 5 (1:2:3:4:undefined)
?
So it does seem to matter how much of the list it evaluates...
take evaluates as much as it needs of the spine but not any of the elements. Even then, take is a good producer, so take 1 . take 5 $ 1:2:3:4:undefined will converge. But I think you know all this and your questions are rhetorical :) Jules
participants (3)
-
Jules Bean
-
Miguel Mitrofanov
-
Peter Gammie