global variable

Jon Fairbairn Jon.Fairbairn at
Sun Oct 12 21:45:30 EDT 2003

On 2003-10-12 at 20:20BST Jose Morais wrote:
> Hello,
> 	I need a function called, say, newItem, that when
> first called returns 1, the next time it is called it
> would return 2, then 3 and so on. How can I achieve this?

You can't (as Glynn has explained), and most of the time
it's the wrong thing to do anyway. Apart from the monadic
approach (which is perhaps a bit heavyweight), another way
of tackling this sort of thing is to used infinite lists.

item_numbers:: [Integer]
item_numbers = [1..]

You can then operate on those with map and fold.


Jón Fairbairn                                 Jon.Fairbairn at

More information about the Haskell-Cafe mailing list