Skip to content

Commit cf954e6

Browse files
Introduce tuple vs elements (#37318)
* Introduce tuple vs elements * Update docs/fsharp/language-reference/arrays.md --------- Co-authored-by: Bill Wagner <[email protected]>
1 parent 17e569f commit cf954e6

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

docs/fsharp/language-reference/arrays.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,27 @@ You can also put each element on a separate line, in which case the semicolon se
1818

1919
[!code-fsharp[Main](~/samples/snippets/fsharp/arrays/snippet2.fs)]
2020

21-
The type of the array elements is inferred from the literals used and must be consistent. The following code causes an error because 1.0 is a float and 2 and 3 are integers.
21+
The type of the array elements is inferred from the literals used and must be consistent.
2222

2323
```fsharp
24-
// Causes an error.
25-
// let array2 = [| 1.0; 2; 3 |]
24+
// This is an array of 3 integers.
25+
let array1 = [| 1; 2; 3 |]
26+
// This is an array of a tuple of 3 integers.
27+
let array2 = [| 1, 2, 3 |]
28+
```
29+
30+
The following code causes an error because 3.0 is a float and 1 and 2 are integers.
31+
32+
```fsharp
33+
// Causes an error. The 3.0 (float) cannot be converted to integer implicitly.
34+
// let array3 = [| 1; 2; 3.0 |]
35+
```
36+
37+
The following code causes an error too because `1,2` is a tuple and `3` is an integer.
38+
39+
```fsharp
40+
// Causes an error too. The 3 (integer) cannot be converted to tuple implicitly.
41+
// let array4 = [| 1, 2; 3 |]
2642
```
2743

2844
You can also use sequence expressions to create arrays. Following is an example that creates an array of squares of integers from 1 to 10.

0 commit comments

Comments
 (0)