[Haskell-cafe] Change value of a variable

2009-06-07 Thread ptrash
Hi, how can I change the value of a variable. let x = 1 x = x + 2 First I set the value of x to 1. Then I want to increase it by 2. This way doesn't work, because I think it is a infinite expression. Is there a way to change the value? -- View this message in context: http://www.nabble.com

Re: [Haskell-cafe] Change value of a variable

2009-06-07 Thread Bulat Ziganshin
Hello ptrash, Sunday, June 7, 2009, 9:41:56 PM, you wrote: > Hi, how can I change the value of a variable. there are no variables in haskell :))) x, like any other identifier, is a value. when you translate to Haskell some algo that needs to update variable contents, you may either 1) use recu

Re: [Haskell-cafe] Change value of a variable

2009-06-07 Thread Keith Sheppard
I guess the short answer is that it is not possible. 'x' is immutable and if you want a different value than 'x' that expression has to be given a different name like: let x=1 y=x+2 ... But I'm not sure if that helps you. Haskell does things very differently than the imperative languages a

Re: [Haskell-cafe] Change value of a variable

2009-06-07 Thread ptrash
Hi, thanks for the answers. I want to make something like a counter. I have written a recursive method which for example runs x times and counts how many times it runs, and also count some other thinks. Add the end I want a statistic about certain thinks returned by the method. -- View this mess

Re: [Haskell-cafe] Change value of a variable

2009-06-07 Thread Deniz Dogan
2009/6/7 ptrash : > > Hi, thanks for the answers. > > I want to make something like a counter. I have written a recursive method > which for example runs x times and counts how many times it runs, and also > count some other thinks. Add the end I want a statistic about certain thinks > returned by

Re: [Haskell-cafe] Change value of a variable

2009-06-07 Thread Ketil Malde
ptrash writes: > I want to make something like a counter. I have written a recursive method > which for example runs x times and counts how many times it runs, and also > count some other thinks. Add the end I want a statistic about certain thinks > returned by the method. Keep in mind that a fu

Re: [Haskell-cafe] Change value of a variable

2009-06-07 Thread ptrash
What i am exactly to do is this: I have a list of pupils (type Pupil = (Name, Grade)) where I store the name of the pupil and which grade he has. No I want to get the number (and average number) of each grade. Something like 10 Pupils have a A (23%), 2 Pupils have a B ( 4 %) etc -- View this mes

Re: [Haskell-cafe] Change value of a variable

2009-06-07 Thread Jeff Heard
Sounds like a fold to me. Try looking at the doc of either foldl/r/l' or mapAccum depending on what you want.. Then write a function for one iteration that returns the value from that iteration combined with the value from the last iteration -- Jeff On Sun, Jun 7, 2009 at 3:44 PM, ptrash wrote:

Re[2]: [Haskell-cafe] Change value of a variable

2009-06-07 Thread Bulat Ziganshin
Hello ptrash, Sunday, June 7, 2009, 11:03:55 PM, you wrote: > Hi, thanks for the answers. > I want to make something like a counter. I have written a recursive method > which for example runs x times and counts how many times it runs, and also > count some other thinks. Add the end I want a stat

Re[2]: [Haskell-cafe] Change value of a variable

2009-06-07 Thread Bulat Ziganshin
Hello ptrash, Sunday, June 7, 2009, 11:44:18 PM, you wrote: > I have a list of pupils (type Pupil = (Name, Grade)) where I store the name > of the pupil and which grade he has. No I want to get the number (and > average number) of each grade. Something like 10 Pupils have a A (23%), 2 > Pupils ha