Writing a counter function

Shlomi Fish shlomif@vipe.technion.ac.il
Sat, 29 Jun 2002 18:58:37 +0300 (IDT)


On Sat, 29 Jun 2002, Hannah Schroeter wrote:

> Hello!
>
> On Sat, Jun 29, 2002 at 06:23:27PM +0300, Shlomi Fish wrote:
> > [...]
>
> > Actually, I'd like a more generalized counter. Something that would return
> > both the number and a handler to add another number, which in turn would
> > return the new sum and a new handler, etc.
>
> That's just what lazy lists are for. The "handler" thing is done
> automatically thanks to lazy evaluation.
>
> I.e. countFrom n = n : countFrom (n + 1)
> or just countFrom n = [n..]
>

No. But I want to generate an irregular series, which I determine the
intervals between two consecutive numbers myself. E.g:

let (num1, next1) = (counter 5)
    (num2, next2) = (next1 100)
    (num3, next3) = (next2 50) in
    [num1,num2,num3]

Will have the numbers [5, 105, 155].

Regards,

	Shlomi Fish

> Kind regards,
>
> Hannah.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



----------------------------------------------------------------------
Shlomi Fish        shlomif@vipe.technion.ac.il
Home Page:         http://t2.technion.ac.il/~shlomif/
Home E-mail:       shlomif@iglu.org.il

He who re-invents the wheel, understands much better how a wheel works.