Skip to content

Commit 049a1a7

Browse files
authored
Merge pull request #26727 from dsyme/f6
F# 6 doc revamp
2 parents ac3f51c + 1262126 commit 049a1a7

File tree

74 files changed

+859
-404
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+859
-404
lines changed

.openpublishing.redirection.json

+20-2
Original file line numberDiff line numberDiff line change
@@ -12967,13 +12967,26 @@
1296712967
"source_path": "docs/fsharp/async.md",
1296812968
"redirect_url": "/dotnet/fsharp/tutorials/asynchronous-and-concurrent-programming/async"
1296912969
},
12970+
{
12971+
"source_path": "docs/fsharp/language-reference/asynchronous-workflows.md",
12972+
"redirect_url": "/dotnet/fsharp/docs/fsharp/language-reference/async-expressions"
12973+
},
1297012974
{
1297112975
"source_path": "docs/fsharp/getting-started-netcore.md",
1297212976
"redirect_url": "/dotnet/fsharp/get-started/get-started-command-line"
1297312977
},
1297412978
{
1297512979
"source_path": "docs/fsharp/introduction-to-functional-programming/functions-as-first-class-values.md",
12976-
"redirect_url": "/dotnet/fsharp/introduction-to-functional-programming/first-class-functions",
12980+
"redirect_url": "/dotnet/fsharp/tutorials/using-functions",
12981+
"redirect_document_id": true
12982+
},
12983+
{
12984+
"source_path": "docs/fsharp/introduction-to-functional-programming/first-class-functions.md",
12985+
"redirect_url": "/dotnet/fsharp/tutorials/using-functions"
12986+
},
12987+
{
12988+
"source_path": "docs/fsharp/introduction-to-functional-programming/index.md",
12989+
"redirect_url": "/dotnet/fsharp/tutorials/functional-programming-concepts",
1297712990
"redirect_document_id": true
1297812991
},
1297912992
{
@@ -12996,7 +13009,12 @@
1299613009
},
1299713010
{
1299813011
"source_path": "docs/fsharp/tutorials/asynchronous-and-concurrent-programming/index.md",
12999-
"redirect_url": "/dotnet/fsharp/tutorials/asynchronous-and-concurrent-programming/async"
13012+
"redirect_url": "/dotnet/fsharp/tutorials/async"
13013+
},
13014+
{
13015+
"source_path": "docs/fsharp/tutorials/asynchronous-and-concurrent-programming/async.md",
13016+
"redirect_url": "/dotnet/fsharp/tutorials/async",
13017+
"redirect_document_id": true
1300013018
},
1300113019
{
1300213020
"source_path": "docs/fsharp/tutorials/getting-started/getting-started-command-line.md",

docs/fsharp/get-started/get-started-command-line.md

+24-31
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Get started with F# with command-line tools
33
description: Learn how to build a simple multi-project solution on F# using the .NET CLI on any operating system (Windows, macOS, or Linux).
4-
ms.date: 08/15/2020
4+
ms.date: 10/29/2021
55
---
66
# Get started with F# with the .NET CLI
77

@@ -15,22 +15,22 @@ This article assumes that you know how to use a command line and have a preferre
1515

1616
## Build a simple multi-project solution
1717

18-
Open a command prompt/terminal and use the [dotnet new](../../core/tools/dotnet-new.md) command to create new solution file called `FSNetCore`:
18+
Open a command prompt/terminal and use the [dotnet new](../../core/tools/dotnet-new.md) command to create new solution file called `FSharpSample`:
1919

2020
```dotnetcli
21-
dotnet new sln -o FSNetCore
21+
dotnet new sln -o FSharpSample
2222
```
2323

2424
The following directory structure is produced after running the previous command:
2525

2626
```console
27-
FSNetCore
28-
├── FSNetCore.sln
27+
FSharpSample
28+
├── FSharpSample.sln
2929
```
3030

3131
### Write a class library
3232

33-
Change directories to *FSNetCore*.
33+
Change directories to *FSharpSample*.
3434

3535
Use the `dotnet new` command, create a class library project in the **src** folder named Library.
3636

@@ -41,8 +41,8 @@ dotnet new classlib -lang "F#" -o src/Library
4141
The following directory structure is produced after running the previous command:
4242

4343
```console
44-
└── FSNetCore
45-
├── FSNetCore.sln
44+
└── FSharpSample
45+
├── FSharpSample.sln
4646
└── src
4747
└── Library
4848
├── Library.fs
@@ -54,20 +54,14 @@ Replace the contents of `Library.fs` with the following code:
5454
```fsharp
5555
module Library
5656
57-
open Newtonsoft.Json
57+
open System.Text.Json
5858
59-
let getJsonNetJson value =
60-
let json = JsonConvert.SerializeObject(value)
61-
$"I used to be {value} but now I'm {json} thanks to Json.NET!"
59+
let getJson value =
60+
let json = JsonSerializer.Serialize(value)
61+
value, json
6262
```
6363

64-
Add the Newtonsoft.Json NuGet package to the Library project.
65-
66-
```dotnetcli
67-
dotnet add src/Library/Library.fsproj package Newtonsoft.Json
68-
```
69-
70-
Add the `Library` project to the `FSNetCore` solution using the [dotnet sln add](../../core/tools/dotnet-sln.md) command:
64+
Add the `Library` project to the `FSharpSample` solution using the [dotnet sln add](../../core/tools/dotnet-sln.md) command:
7165

7266
```dotnetcli
7367
dotnet sln add src/Library/Library.fsproj
@@ -86,8 +80,8 @@ dotnet new console -lang "F#" -o src/App
8680
The following directory structure is produced after running the previous command:
8781

8882
```console
89-
└── FSNetCore
90-
├── FSNetCore.sln
83+
└── FSharpSample
84+
├── FSharpSample.sln
9185
└── src
9286
├── App
9387
│ ├── App.fsproj
@@ -104,12 +98,12 @@ open System
10498
open Library
10599
106100
[<EntryPoint>]
107-
let main argv =
108-
printfn "Nice command-line arguments! Here's what Json.NET has to say about them:"
101+
let main args =
102+
printfn "Nice command-line arguments! Here's what System.Text.Json has to say about them:"
109103
110-
for arg in argv do
111-
let value = getJsonNetJson arg
112-
printfn $"{value}"
104+
let value, json = getJson {| args=args; year=System.DateTime.Now.Year |}
105+
printfn $"Input: %0A{value}"
106+
printfn $"Output: %s{json}"
113107
114108
0 // return an integer exit code
115109
```
@@ -120,7 +114,7 @@ Add a reference to the `Library` project using [dotnet add reference](../../core
120114
dotnet add src/App/App.fsproj reference src/Library/Library.fsproj
121115
```
122116

123-
Add the `App` project to the `FSNetCore` solution using the `dotnet sln add` command:
117+
Add the `App` project to the `FSharpSample` solution using the `dotnet sln add` command:
124118

125119
```dotnetcli
126120
dotnet sln add src/App/App.fsproj
@@ -138,10 +132,9 @@ dotnet run Hello World
138132
You should see the following results:
139133

140134
```console
141-
Nice command-line arguments! Here's what Json.NET has to say about them:
142-
143-
I used to be Hello but now I'm ""Hello"" thanks to Json.NET!
144-
I used to be World but now I'm ""World"" thanks to Json.NET!
135+
Nice command-line arguments! Here's what System.Text.Json has to say about them:
136+
Input: { args = [|"Hello"; "World"|] year = 2021 }
137+
Output: {"args":["Hello","World"],"year":2021}
145138
```
146139

147140
## Next steps

docs/fsharp/get-started/get-started-visual-studio.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
title: Get started with F# in Visual Studio
33
description: Learn how to use F# with Visual Studio.
4-
ms.date: 12/20/2019
4+
ms.date: 10/29/2021
55
recommendations: false
66
---
77
# Get started with F# in Visual Studio
88

9-
F# and the Visual F# tooling are supported in the Visual Studio integrated development environment (IDE).
9+
F# is supported in the Visual Studio integrated development environment (IDE).
1010

1111
To begin, ensure that you have [Visual Studio installed with F# support](install-fsharp.md#install-f-with-visual-studio).
1212

@@ -35,10 +35,10 @@ Let's get started by writing some code. Make sure that the `Program.fs` file is
3535
The previous code sample defines a function called `square` that takes an input named `x` and multiplies it by itself. Because F# uses [Type inference](../language-reference/type-inference.md), the type of `x` doesn't need to be specified. The F# compiler understands the types where multiplication is valid and assigns a type to `x` based on how `square` is called. If you hover over `square`, you should see the following:
3636

3737
```fsharp
38-
val square: x:int -> int
38+
val square: x: int -> int
3939
```
4040

41-
This is what is known as the function's type signature. It can be read like this: "Square is a function that takes an integer named x and produces an integer". The compiler gave `square` the `int` type for now; this is because multiplication is not generic across *all* types but rather a closed set of types. The F# compiler will adjust the type signature if you call `square` with a different input type, such as a `float`.
41+
This is what is known as the function's type signature. It can be read like this: "Square is a function that takes an integer named x and produces an integer". The compiler gave `square` the `int` type for now.
4242

4343
Another function, `main`, is defined, which is decorated with the `EntryPoint` attribute. This attribute tells the F# compiler that program execution should start there. It follows the same convention as other [C-style programming languages](https://en.wikipedia.org/wiki/Entry_point#C_and_C.2B.2B), where command-line arguments can be passed to this function, and an integer code is returned (typically `0`).
4444

docs/fsharp/get-started/get-started-vscode.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Get Started with F# in Visual Studio Code
33
description: Learn how to use F# with Visual Studio Code and the Ionide plugin suite.
4-
ms.date: 07/23/2021
4+
ms.date: 10/29/2021
55
---
66
# Get Started with F# in Visual Studio Code
77

@@ -55,7 +55,7 @@ toPigLatin "banana";;
5555
You should see the following result:
5656

5757
```fsharp
58-
val it : string = "ananabay"
58+
val it: string = "ananabay"
5959
```
6060

6161
Now, let's try with a vowel as the first letter. Enter the following:
@@ -67,7 +67,7 @@ toPigLatin "apple";;
6767
You should see the following result:
6868

6969
```fsharp
70-
val it : string = "appleyay"
70+
val it: string = "appleyay"
7171
```
7272

7373
The function appears to be working as expected. Congratulations, you just wrote your first F# function in Visual Studio Code and evaluated it with FSI!
@@ -86,7 +86,7 @@ If the first character in a word starts with a vowel, add "yay" to the end of th
8686
You may have noticed the following in FSI:
8787

8888
```fsharp
89-
val toPigLatin : word:string -> string
89+
val toPigLatin: word: string -> string
9090
```
9191

9292
This states that `toPigLatin` is a function that takes in a `string` as input (called `word`), and returns another `string`. This is known as the [type signature of the function](https://fsharpforfunandprofit.com/posts/function-signatures/), a fundamental piece of F# that's key to understanding F# code. You'll also notice this if you hover over the function in Visual Studio Code.
@@ -125,10 +125,10 @@ Now, in the `main` function, call your Pig Latin generator function on the argum
125125

126126
```fsharp
127127
[<EntryPoint>]
128-
let main argv =
129-
for name in argv do
130-
let newName = PigLatin.toPigLatin name
131-
printfn "%s in Pig Latin is: %s" name newName
128+
let main args =
129+
for arg in args do
130+
let newArg = PigLatin.toPigLatin arg
131+
printfn "%s in Pig Latin is: %s" arg newArg
132132
133133
0
134134
```

docs/fsharp/get-started/get-started-with-visual-studio-for-mac.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: Get started with F# in Visual Studio for Mac
33
description: Learn how to use F# with Visual Studio for Mac.
4-
ms.date: 07/03/2018
4+
ms.date: 10/29/2021
55
---
66
# Get started with F# in Visual Studio for Mac
77

8-
F# and the Visual F# tooling are supported in the Visual Studio for Mac IDE. Ensure that you have [Visual Studio for Mac installed](install-fsharp.md#install-f-with-visual-studio-for-mac).
8+
F# is supported in the Visual Studio for Mac IDE. Ensure that you have [Visual Studio for Mac installed](install-fsharp.md#install-f-with-visual-studio-for-mac).
99

1010
## Creating a console application
1111

@@ -53,14 +53,14 @@ Congratulations! You've created your first F# project in Visual Studio for Mac,
5353

5454
## Using F# Interactive
5555

56-
One of the best features of the Visual F# tooling in Visual Studio for Mac is the F# Interactive Window. It allows you to send code over to a process where you can call that code and see the result interactively.
56+
One of the best features of F# tooling in Visual Studio for Mac is the F# Interactive Window. It allows you to send code over to a process where you can call that code and see the result interactively.
5757

5858
To begin using it, highlight the `square` function defined in your code. Next, click on **Edit** from the top level menu. Next select **Send selection to F# Interactive**. This executes the code in the F# Interactive Window. Alternatively, you can right click on the selection and choose **Send selection to F# Interactive**. You should see the F# Interactive Window appear with the following in it:
5959

6060
```console
6161
>
6262

63-
val square : x:int -> int
63+
val square: x: int -> int
6464

6565
>
6666
```
@@ -69,34 +69,34 @@ This shows the same function signature for the `square` function, which you saw
6969

7070
```console
7171
> square 12;;
72-
val it : int = 144
73-
>square 13;;
74-
val it : int = 169
72+
val it: int = 144
73+
> square 13;;
74+
val it: int = 169
7575
```
7676

7777
This executes the function, binds the result to a new name `it`, and displays the type and value of `it`. Note that you must terminate each line with `;;`. This is how F# Interactive knows when your function call is finished. You can also define new functions in F# Interactive:
7878

7979
```console
8080
> let isOdd x = x % 2 <> 0;;
8181

82-
val isOdd : x:int -> bool
82+
val isOdd: x: int -> bool
8383

8484
> isOdd 12;;
85-
val it : bool = false
85+
val it: bool = false
8686
```
8787

8888
The above defines a new function, `isOdd`, which takes an `int` and checks to see if it's odd! You can call this function to see what it returns with different inputs. You can call functions within function calls:
8989

9090
```console
9191
> isOdd (square 15);;
92-
val it : bool = true
92+
val it: bool = true
9393
```
9494

9595
You can also use the [pipe-forward operator](../language-reference/symbol-and-operator-reference/index.md) to pipeline the value into the two functions:
9696

9797
```console
9898
> 15 |> square |> isOdd;;
99-
val it : bool = true
99+
val it: bool = true
100100
```
101101

102102
The pipe-forward operator, and more, are covered in later tutorials.

docs/fsharp/get-started/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Get started with F#
33
description: Find out how to get started with the F# programming language.
4-
ms.date: 09/12/2020
4+
ms.date: 10/29/2021
55
---
66
# Get Started with F\#
77

docs/fsharp/get-started/install-fsharp.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Install F#
33
description: Learn how to install F# in various different ways.
4-
ms.date: 12/20/2019
4+
ms.date: 10/29/2021
55
---
66
# Install F\#
77

docs/fsharp/index.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ metadata:
99
ms.topic: landing-page # Required
1010
author: cartermp
1111
ms.author: phcart
12-
ms.date: 07/28/2021
12+
ms.date: 10/29/2021
1313

1414
landingContent:
1515
- title: "Learn to program in F#"
@@ -53,12 +53,12 @@ landingContent:
5353
url: style-guide/conventions.md
5454
- linkListType: tutorial
5555
links:
56-
- text: "Introduction to Functional Programming in F#"
57-
url: introduction-to-functional-programming/index.md
58-
- text: "First-class functions"
59-
url: introduction-to-functional-programming/first-class-functions.md
56+
- text: "Functional programming concepts in F#"
57+
url: tutorials/functional-programming-concepts.md
58+
- text: "Using Functions in F#"
59+
url: tutorials/using-functions.md
6060
- text: "Async programming in F#"
61-
url: tutorials/asynchronous-and-concurrent-programming/async.md
61+
url: tutorials/async.md
6262
- text: "Type providers"
6363
url: tutorials/type-providers/index.md
6464

docs/fsharp/language-reference/active-patterns.md

+16
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,22 @@ Note however that only single-case active patterns can be parameterized.
132132

133133
[!code-fsharp[Main](~/samples/snippets/fsharp/lang-ref-2/snippet5008.fs)]
134134

135+
## Struct Representations for Partial Active Patterns
136+
137+
By default, partial active patterns return an `option` value, which will involve an allocation for the `Some` value on a successful match. Alternatively, you can use a [value option](value-options.md) as a return value through the use of the `Struct` attribute:
138+
139+
```fsharp
140+
open System
141+
142+
[<return: Struct>]
143+
let (|Int|_|) str =
144+
match Int32.TryParse(str) with
145+
| (true, n) -> ValueSome n
146+
| _ -> ValueNone
147+
```
148+
149+
The attribute must be specified, because the use of a struct return is not inferred from simply changing the return type to `ValueOption`. For more information, see [RFC FS-1039](https://github.com/fsharp/fslang-design/blob/main/FSharp-6.0/FS-1039-struct-representation-for-active-patterns.md).
150+
135151
## See also
136152

137153
- [F# Language Reference](index.md)

docs/fsharp/language-reference/anonymous-records.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ It is possible to use a .NET API that requires the use of [C# anonymous types](.
240240
open System.Linq
241241
242242
let names = [ "Ana"; "Felipe"; "Emilia"]
243-
let nameGrouping = names.Select(fun n -> {| Name = n; FirstLetter = n.[0] |})
243+
let nameGrouping = names.Select(fun n -> {| Name = n; FirstLetter = n[0] |})
244244
for ng in nameGrouping do
245245
printfn $"{ng.Name} has first letter {ng.FirstLetter}"
246246
```

0 commit comments

Comments
 (0)