``` 你好我试图通过创建以下方法来了解累加器如何工作：
它接收一个数字并创建一个元组:( `(sum [0..nr], [0..nr])` 。 例如，给定`4` ，它应该返回`(10, [0,1,2,3,4])` 。
这是我的代码：
```accu :: Int -> (Int, [Int])
accu 0  = (0, )
accu nr = go (0, []) nr where   --I do not get this line, mainly the first argument
go (s,ls) 0  = (s, 0:ls)
go (s,ls) nr = go (s+nr, nr:ls) (nr-1)
```
我不明白累加器如何改变它的值，因为它不是一个函数，因此它不应该是不可变的？ 在我的情况下，它不应该像一个常数吗？ Hello i am trying to understand how do accumulators work by creating the following method :
It receives a number and it creates a tuple of: `(sum [0..nr], [0..nr])`. For instance, given `4`, it should return `(10, [0,1,2,3,4])`.
This is the code I have:
```accu :: Int -> (Int, [Int])
accu 0  = (0, )
accu nr = go (0, []) nr where   --I do not get this line, mainly the first argument
go (s,ls) 0  = (s, 0:ls)
go (s,ls) nr = go (s+nr, nr:ls) (nr-1)
```
I do not understand how the accumulator changes its value, since it is not a function, and thus shouldn't it be immutable? Shouldn't it be like a constant in my case?原文：https://stackoverflow.com/questions/49444631```

## 最满意答案

``` `go`是一个使用`where`关键字在本地定义的函数，然后直接在`accu`函数中使用。 看看这里： http ： //learnyouahaskell.com/syntax-in-functions#where
这意味着累加器并没有真正改变，它只是每次递归调用`go`函数时的不同累加器。 最后一行将使用新的累加器值递归调用`go`函数。 `go` is a function that is locally defined using the `where` keyword and then used directly in the `accu` function. Have a look here: http://learnyouahaskell.com/syntax-in-functions#where
That means the accumulator does not really change, it is just a different accumulator in each recursive call to the `go` function. The last line will recursively call the `go` function with a new accumulator value.```
2018-03-23