Skip to content

Commit 429ba85

Browse files
authored
Doc correction - Fix issue number - #34333 (#35592)
* Fixes issue number #35206 * fix fibonacci example issue #34333 * Modified sequences.md for output of fibonacci example * Modified sequences.md file
1 parent 5f9b147 commit 429ba85

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

docs/fsharp/language-reference/sequences.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ You can define infinite sequences by using the [Seq.initInfinite](https://fsharp
114114

115115
[!code-fsharp[Main](~/samples/snippets/fsharp/fssequences/snippet13.fs)]
116116

117-
[Seq.unfold](https://fsharp.github.io/fsharp-core-docs/reference/fsharp-collections-seqmodule.html#unfold) generates a sequence from a computation function that takes a state and transforms it to produce each subsequent element in the sequence. The state is just a value that is used to compute each element, and can change as each element is computed. The second argument to `Seq.unfold` is the initial value that is used to start the sequence. `Seq.unfold` uses an option type for the state, which enables you to terminate the sequence by returning the `None` value. The following code shows two examples of sequences, `seq1` and `fib`, that are generated by an `unfold` operation. The first, `seq1`, is just a simple sequence with numbers up to 20. The second, `fib`, uses `unfold` to compute the Fibonacci sequence. Because each element in the Fibonacci sequence is the sum of the previous two Fibonacci numbers, the state value is a tuple that consists of the previous two numbers in the sequence. The initial value is `(1,1)`, the first two numbers in the sequence.
117+
[Seq.unfold](https://fsharp.github.io/fsharp-core-docs/reference/fsharp-collections-seqmodule.html#unfold) generates a sequence from a computation function that takes a state and transforms it to produce each subsequent element in the sequence. The state is just a value that is used to compute each element, and can change as each element is computed. The second argument to `Seq.unfold` is the initial value that is used to start the sequence. `Seq.unfold` uses an option type for the state, which enables you to terminate the sequence by returning the `None` value. The following code shows two examples of sequences, `seq1` and `fib`, that are generated by an `unfold` operation. The first, `seq1`, is just a simple sequence with numbers up to 20. The second, `fib`, uses `unfold` to compute the Fibonacci sequence. Because each element in the Fibonacci sequence is the sum of the previous two Fibonacci numbers, the state value is a tuple that consists of the previous two numbers in the sequence. The initial value is `(0,1)`, the first two numbers in the sequence.
118118

119119
[!code-fsharp[Main](~/samples/snippets/fsharp/fssequences/snippet14.fs)]
120120

@@ -127,7 +127,7 @@ The sequence seq1 contains numbers from 0 to 20.
127127

128128
The sequence fib contains Fibonacci numbers.
129129

130-
2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
130+
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
131131
```
132132

133133
The following code is an example that uses many of the sequence module functions described here to generate and compute the values of infinite sequences. The code might take a few minutes to run.

samples/snippets/fsharp/fssequences/snippet14.fs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ for x in seq1 do
1212
printf "%d " x
1313

1414
let fib =
15-
(1, 1) // Initial state
15+
(0, 1)
1616
|> Seq.unfold (fun state ->
17-
if (snd state > 1000) then
17+
let cur, next = state
18+
if cur < 0 then // overflow
1819
None
1920
else
20-
Some(fst state + snd state, (snd state, fst state + snd state)))
21+
let next' = cur + next
22+
let state' = next, next'
23+
Some (cur, state') )
2124

2225
printfn "\nThe sequence fib contains Fibonacci numbers."
2326
for x in fib do printf "%d " x

0 commit comments

Comments
 (0)