Re: Writing a counter function

2002-07-02 Thread Matt Harden
John Hughes wrote: > On Sun, 30 Jun 2002, Jon Cast wrote: > >>Mark Carroll <[EMAIL PROTECTED]> wrote: >> >>>On Sat, 29 Jun 2002, Samuel E. Moelius III wrote: >>>(snip) >>> Here's another not-exactly-what-you-wanted solution. :) >>> >>>(snip) >> >>>Do any of the experimental extensions to Ha

Re: Writing a counter function

2002-07-01 Thread Jon Fairbairn
Mark Carroll <[EMAIL PROTECTED]> 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

Re: Writing a counter function

2002-07-01 Thread Frank Atanassow
Shlomi Fish wrote (on 29-06-02 17:30 +0300): > > I'm trying to write a counter function that would return a tuple whose > first element is the current value and whose second element is a new > counter. John Hughes showed how to do this. Here is a closely related, more abstract solution which emp

Re: Writing a counter function

2002-06-30 Thread Andrew J Bromage
G'day all. On Sun, Jun 30, 2002 at 01:51:56PM +0100, Peter G. Hancock wrote: > Why not have a monad m a = Int -> (a,Int) which is a state monad plus > the operation bump : Int -> m Int > > bump k n = (n,n+k) Oh, ye of insufficient genericity. We can do better than that... import Mo

Re: Writing a counter function

2002-06-30 Thread Peter G. Hancock
> lmichele wrote (on Sun, 30 Jun 2002 at 09:26): > By the way, what's the purpose of this coding? (this is the type of > question: "ok, I have a hammer, now, for what kind of nail it is useful?") I would guess that something like the asked-for counter could be useful if one is allo

Re: Writing a counter function

2002-06-30 Thread Mark Carroll
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 questio

Re: Writing a counter function

2002-06-30 Thread Jon Fairbairn
Mark Carrol wrote: > The beauty of his request was that it was so simple and seemed to make > sense; 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

RE: Writing a counter function

2002-06-30 Thread A./C. Luis Pablo Michelena
s is the type of question: "ok, I have a hammer, now, for what kind of nail it is useful?") Cheers, Luis Michelena - Original Message - From: Shlomi Fish <[EMAIL PROTECTED]> To: Hannah Schroeter <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Saturday,

Re: Writing a counter function

2002-06-30 Thread Andrew J Bromage
G'day all. On Sat, Jun 29, 2002 at 05:26:46PM -0500, Mark Carroll wrote: > Do any of the experimental extensions to Haskell allow a what-he-wanted > solution? I couldn't arrange one in H98 without something having an > infinitely-recursive type signature. I'm sure it would have been easy in > Li

Re: Writing a counter function

2002-06-30 Thread John Hughes
On Sun, 30 Jun 2002, Jon Cast wrote: > > Mark Carroll <[EMAIL PROTECTED]> wrote: > > On Sat, 29 Jun 2002, Samuel E. Moelius III wrote: > > (snip) > > > Here's another not-exactly-what-you-wanted solution. :) > > (snip) > > > Do any of the experimental extensions to Haskell allow a > > what-he-wa

Re: Writing a counter function

2002-06-29 Thread Jon Cast
Mark Carroll <[EMAIL PROTECTED]> wrote: > On Sat, 29 Jun 2002, Samuel E. Moelius III wrote: > (snip) > > Here's another not-exactly-what-you-wanted solution. :) > (snip) > Do any of the experimental extensions to Haskell allow a > what-he-wanted solution? I couldn't arrange one in H98 without >

Re: Writing a counter function

2002-06-29 Thread that jefu guy
On Sat, 2002-06-29 at 15:26, Mark Carroll wrote: > On Sat, 29 Jun 2002, Samuel E. Moelius III wrote: > (snip) > > Here's another not-exactly-what-you-wanted solution. :) > (snip) > > Do any of the experimental extensions to Haskell allow a what-he-wanted > solution? I couldn't arrange one in H98

Re: Writing a counter function

2002-06-29 Thread Mark Carroll
On Sat, 29 Jun 2002, Samuel E. Moelius III wrote: (snip) > Here's another not-exactly-what-you-wanted solution. :) (snip) Do any of the experimental extensions to Haskell allow a what-he-wanted solution? I couldn't arrange one in H98 without something having an infinitely-recursive type signatur

Re: Writing a counter function

2002-06-29 Thread Samuel E. Moelius III
> 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].

Re: Writing a counter function

2002-06-29 Thread Samuel E. Moelius III
> 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].

Re: Writing a counter function

2002-06-29 Thread John Hughes
On Sat, 29 Jun 2002, Shlomi Fish wrote: > > 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

Re: Writing a counter function

2002-06-29 Thread Shlomi Fish
Just for the record, here is a Perl function that does this: ### sub counter { my $a = shift; my $next = sub { my $to_add = shift ; return counter($to_add+$a); }; return ($a, $next); } my ($result,$next) = counter(5); my ($result2, $next2) = $next->

Re: Writing a counter function

2002-06-29 Thread Shlomi Fish
On Sat, 29 Jun 2002, Jon Fairbairn wrote: > Shlomi Fish wrote: > > 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) = (

Re: Writing a counter function

2002-06-29 Thread Jon Fairbairn
Shlomi Fish wrote: > 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 n

Re: Writing a counter function

2002-06-29 Thread Shlomi Fish
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

Re: Writing a counter function

2002-06-29 Thread Hannah Schroeter
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

Re: Writing a counter function

2002-06-29 Thread Shlomi Fish
On Sat, 29 Jun 2002, Mark Carroll wrote: > On Sat, 29 Jun 2002, Shlomi Fish wrote: > (snip) > > counter n = (n,(counter (n+1))) > (snip) > > This doesn't work because you seem to be defining an infinitely deep tuple > (1,(2,(3,(4,() which is naughty. > > I'm not really sure what alternati

Re: Writing a counter function

2002-06-29 Thread Mark Carroll
On Sat, 29 Jun 2002, Shlomi Fish wrote: (snip) > counter n = (n,(counter (n+1))) (snip) This doesn't work because you seem to be defining an infinitely deep tuple (1,(2,(3,(4,() which is naughty. I'm not really sure what alternative to suggest beyond [n .. ] without knowing more about wh