# Folding an infinite list

One big difference is that right folds work on infinite lists, whereas left ones don’t! To put it plainly, if you take an infinite list at some point and you fold it up from the right, you’ll eventually reach the beginning of the list. However, if you take an infinite list at a point and you try to fold it up from the left, you’ll never reach an end!

Learn You a Haskell for Great Good!

Note that the key difference between a left and a right fold is not the order in which the list is traversed, which is always from left to right, but rather how the resulting function applications are nested.

• With foldr, they are nested on “the inside”

foldr f y (x:xs) = f x (foldr f y xs)

Here, the first iteration will result in the outermost application of f. Thus, f has the opportunity to be lazy so that the second argument is either not always evaluated, or it can produce some part of a data structure without forcing its second argument.

• With foldl, they are nested on “the outside”

foldl f y (x:xs) = foldl f (f x y) xs

Here, we can’t evaluate anything until we have reached the outermost application of f, which we will never reach in the case of an infinite list, regardless of whether f is strict or not.

— edited Oct 24 ’11 at 12:21, answered Sep 13 ’11 at 5:17, hammar

— Stack Overflow

2015.08.23 Sunday by ACHK

# Problem 14.1b

A First Course in String Theory

14.1 Counting bosonic states

~~~

Let $N(n, k) = {n + k - 1 \choose k - 1}$, the number of ways to put $n$ indistinguishable balls into $k$ boxes.

p.318 “For open bosonic strings $\alpha' M^2 = N^\perp - 1$, …”

When $\alpha' M^2 = 3$, $N^\perp = 4$, the cases are:

1. four $a_1^\dagger$‘s:

$N(4,24) = 17550$

2. one $a_2^\dagger$ and two $a_1^\dagger$‘s:

$24 \times N(2,24) = 24 \times 300$

3. two $a_2^\dagger$‘s:

$N(2,24) = 300$

4. one $a_3^\dagger$ and one $a_1^\dagger$:

$24 \times 24 = 576$

5. one $a_4^\dagger$:

$24$

Total number of possible states for $N^\perp = 4$ is 25650.

— Me@2015-08-13 12:05:57 PM

# 回到過去 1.2

— Me@2015-07-27 09:01:17 PM

— Me@2015-08-07 08:01:48 PM

# 注定外傳 1.3

（問：不是呀。在量子力學中，即使有兩組百分百一樣的物理系統，即使它們獲得完全相同的輸入，都可能有不同的輸出。）

— Me@2015-08-04 07:57:59 AM