Writing a counter function

Jon Fairbairn Jon.Fairbairn@cl.cam.ac.uk
Mon, 01 Jul 2002 11:10:15 +0100


Mark Carroll <mark@chaos.x-philes.com> wrote:
> On Sun, 30 Jun 2002, Jon Fairbairn wrote:
> (snip)
> > But there's the rub. It's not beautiful and it doesn't make
> > much sense. I really wish we could get away from the "How do
> > I convert this imperative code snippet into Haskell"
> > questions into "How do I solve this abstract problem?"
> =

> The question as originally posed didn't seem like it particularly neede=
d
> something imperative though.

That largely misses the point. My objection is to the
mindset behind the question.

> the first bit is very similar to, say,
> =

> 	counter a =3D (a, \to_add -> counter (a + to_add))

Which looks to me like imperative programming. Indeed, the
Monad answer that I posted is imperative programming, it
just happens to be done in Haskell. Stepwise transformation
of a state is, on some occasions, the right answer to a
problem. Unfortunately in this thread we haven't been told
what the problem is. The question is of the form "how do I
make a hammer?" when a hammer is rarely the most appropriate
tool. That's what I'd like to get away from.

  J=F3n


-- =

J=F3n Fairbairn                                 Jon.Fairbairn@cl.cam.ac.u=
k
31 Chalmers Road                                         jf@cl.cam.ac.uk
Cambridge CB1 3SZ            +44 1223 570179 (after 14:00 only, please!)