Jon.Fairbairn at cl.cam.ac.uk
Sun Oct 12 22:59:56 EDT 2003
On 2003-10-12 at 21:23BST Jose Morais wrote:
> Sorry the newbie question and the insistence, but how exactly do I use
> map or fold applied to the infinite list to get successive integers at
> each time?
You don't. The infinite list /is/ all the successive integers.
I think at this point it would be useful if you could say
what you are trying to do -- what programme are you trying
to write, as opposed to what imperative-sounding programming
technique you are trying to duplicate.
For example, where in an imperative language you might print
the first 10 squares by setting a variable to successive
integers, in Haskell you could write:
positive_naturals = [1..]
squares = map (^2) positive_naturals
main = print $ take 10 squares
which has a similar effect
Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk
More information about the Haskell-Cafe