10 Sep 2001 09:50:35 +0200
"Randles" <firstname.lastname@example.org> writes:
> Hi, Im a computer science undergraduate and we are studying haskell
> as part of our course. I have a question on recursion that i'd like
> to receive some sort of answer to.
Are you a tutor, then, since you'd like to receive answers, rather
than working them out yourself?
> The question is to write a function to sum the first n terms in the series:
> 1/1 + 1/3 + 1/5+ .. + 1/(2n-1)
> using ordinary recursion and then using accumulator recursion.
I can think of several ways. For instance, given n as a parameter,
work out the nth term, and make a recursive call thus calculating the
sequence in reverse.
This should be fairly easy to extend with an accumulator, too.
You might get bonus points if you write a function using sum, take,
and map (hint: [1,3..]), or even generate an infinite list of
successive partial sums, and use (!!n) for the result.
> Please help!
But of course!
If I haven't seen further, it is by standing in the footprints of giants