You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
22
22
23
23
```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 |]
26
42
```
27
43
28
44
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