I&#39;m guessing the function looks something like this? (this is common lisp not scheme)<br>
<br>
(let ((counter 0))<br>
  (defun next ()<br>
    (incf counter)   <br>
    counter))<br>
<br>
So the first time you call (next), it returns 1, then 2, etc.<br>
The function (next) is a closure over the variable &#39;counter&#39; and acts by incrementing the variable counter, which is only visible in the scope of the let-block.  As you know in Haskell there is no mutable state (outside of certain monads), so a function like must take place in a monad which allows this, such as IO or ST.  You would probably have to allocate an IORef or STRef which is local to the next function (effectively creating a closure over it).<br>
<br>Cheers,<br> - Tim<br><br><br><div class="gmail_quote">On Wed, Oct 21, 2009 at 12:34 PM, michael rice <span dir="ltr">&lt;<a href="mailto:nowgate@yahoo.com">nowgate@yahoo.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
There&#39;s a thread on the plt-scheme list about creating a function of NO arguments named NEXT that just returns the number of times it&#39;s been called, a piece of cake in Scheme, but how would one do this in Haskell? Would the best approach be to use a State monad?<br>
<br>Michael</td></tr></tbody></table><br>



      <br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>