Skip to content

F# 6 doc revamp #26727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9a5bbc8
Start F# 6 doc revamp
dsyme Oct 29, 2021
f7f4224
Start F# 6 doc revamp
dsyme Oct 29, 2021
22a198f
Start F# 6 doc revamp
dsyme Oct 29, 2021
e8bd106
Start F# 6 doc revamp
dsyme Oct 29, 2021
2bd40df
Start F# 6 doc revamp
dsyme Oct 29, 2021
ea57b90
Start F# 6 doc revamp
dsyme Oct 29, 2021
6df9d27
Start F# 6 doc revamp
dsyme Oct 29, 2021
0411352
ref cells and other F# 6 features
dsyme Oct 29, 2021
dee5afc
add table of types with units
dsyme Oct 29, 2021
f0e2f52
fix link
dsyme Oct 29, 2021
5d2046d
feedback
dsyme Oct 30, 2021
54cd63f
Merge branch 'main' of https://github.com/dotnet/docs into f6
dsyme Oct 30, 2021
7133869
Merge branch 'main' into f6
dsyme Nov 2, 2021
2fd9a65
Update docs/fsharp/language-reference/active-patterns.md
dsyme Nov 2, 2021
485e612
Update docs/fsharp/language-reference/active-patterns.md
dsyme Nov 2, 2021
1a93605
Update docs/fsharp/language-reference/async-expressions.md
dsyme Nov 2, 2021
3d3186e
Update docs/fsharp/language-reference/async-expressions.md
dsyme Nov 2, 2021
705fa04
Update docs/fsharp/language-reference/async-expressions.md
dsyme Nov 2, 2021
55c0c85
Update docs/fsharp/tutorials/using-functions.md
dsyme Nov 2, 2021
c6c5077
Update docs/fsharp/tutorials/using-functions.md
dsyme Nov 2, 2021
621d664
Update docs/fsharp/language-reference/async-expressions.md
dsyme Nov 2, 2021
db2378c
Update docs/fsharp/language-reference/casting-and-conversions.md
dsyme Nov 2, 2021
1d685f5
Update docs/fsharp/language-reference/casting-and-conversions.md
dsyme Nov 2, 2021
5f3b37f
Update docs/fsharp/language-reference/casting-and-conversions.md
dsyme Nov 2, 2021
0d5925b
Update docs/fsharp/language-reference/casting-and-conversions.md
dsyme Nov 2, 2021
a4d18ac
Update docs/fsharp/tutorials/async.md
dsyme Nov 2, 2021
131f8c8
Update docs/fsharp/language-reference/casting-and-conversions.md
dsyme Nov 2, 2021
87532a8
Update index.yml
dsyme Nov 2, 2021
17628ab
Apply suggestions from code review
dsyme Nov 2, 2021
1262126
Update docs/fsharp/language-reference/task-expressions.md
dsyme Nov 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions .openpublishing.redirection.json
Original file line number Diff line number Diff line change
Expand Up @@ -12967,13 +12967,26 @@
"source_path": "docs/fsharp/async.md",
"redirect_url": "/dotnet/fsharp/tutorials/asynchronous-and-concurrent-programming/async"
},
{
"source_path": "docs/fsharp/language-reference/asynchronous-workflows.md",
"redirect_url": "/dotnet/fsharp/docs/fsharp/language-reference/async-expressions"
},
{
"source_path": "docs/fsharp/getting-started-netcore.md",
"redirect_url": "/dotnet/fsharp/get-started/get-started-command-line"
},
{
"source_path": "docs/fsharp/introduction-to-functional-programming/functions-as-first-class-values.md",
"redirect_url": "/dotnet/fsharp/introduction-to-functional-programming/first-class-functions",
"redirect_url": "/dotnet/fsharp/tutorials/using-functions",
"redirect_document_id": true
},
{
"source_path": "docs/fsharp/introduction-to-functional-programming/first-class-functions.md",
"redirect_url": "/dotnet/fsharp/tutorials/using-functions"
},
{
"source_path": "docs/fsharp/introduction-to-functional-programming/index.md",
"redirect_url": "/dotnet/fsharp/tutorials/functional-programming-concepts",
"redirect_document_id": true
},
{
Expand All @@ -12996,7 +13009,12 @@
},
{
"source_path": "docs/fsharp/tutorials/asynchronous-and-concurrent-programming/index.md",
"redirect_url": "/dotnet/fsharp/tutorials/asynchronous-and-concurrent-programming/async"
"redirect_url": "/dotnet/fsharp/tutorials/async"
},
{
"source_path": "docs/fsharp/tutorials/asynchronous-and-concurrent-programming/async.md",
"redirect_url": "/dotnet/fsharp/tutorials/async",
"redirect_document_id": true
},
{
"source_path": "docs/fsharp/tutorials/getting-started/getting-started-command-line.md",
Expand Down
55 changes: 24 additions & 31 deletions docs/fsharp/get-started/get-started-command-line.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Get started with F# with command-line tools
description: Learn how to build a simple multi-project solution on F# using the .NET CLI on any operating system (Windows, macOS, or Linux).
ms.date: 08/15/2020
ms.date: 10/29/2021
---
# Get started with F# with the .NET CLI

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

## Build a simple multi-project solution

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

```dotnetcli
dotnet new sln -o FSNetCore
dotnet new sln -o FSharpSample
```

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

```console
FSNetCore
├── FSNetCore.sln
FSharpSample
├── FSharpSample.sln
```

### Write a class library

Change directories to *FSNetCore*.
Change directories to *FSharpSample*.

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

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

```console
└── FSNetCore
├── FSNetCore.sln
└── FSharpSample
├── FSharpSample.sln
└── src
└── Library
├── Library.fs
Expand All @@ -54,20 +54,14 @@ Replace the contents of `Library.fs` with the following code:
```fsharp
module Library

open Newtonsoft.Json
open System.Text.Json

let getJsonNetJson value =
let json = JsonConvert.SerializeObject(value)
$"I used to be {value} but now I'm {json} thanks to Json.NET!"
let getJson value =
let json = JsonSerializer.Serialize(value)
value, json
```

Add the Newtonsoft.Json NuGet package to the Library project.

```dotnetcli
dotnet add src/Library/Library.fsproj package Newtonsoft.Json
```

Add the `Library` project to the `FSNetCore` solution using the [dotnet sln add](../../core/tools/dotnet-sln.md) command:
Add the `Library` project to the `FSharpSample` solution using the [dotnet sln add](../../core/tools/dotnet-sln.md) command:

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

```console
└── FSNetCore
├── FSNetCore.sln
└── FSharpSample
├── FSharpSample.sln
└── src
├── App
│ ├── App.fsproj
Expand All @@ -104,12 +98,12 @@ open System
open Library

[<EntryPoint>]
let main argv =
printfn "Nice command-line arguments! Here's what Json.NET has to say about them:"
let main args =
printfn "Nice command-line arguments! Here's what System.Text.Json has to say about them:"

for arg in argv do
let value = getJsonNetJson arg
printfn $"{value}"
let value, json = getJson {| args=args; year=System.DateTime.Now.Year |}
printfn $"Input: %0A{value}"
printfn $"Output: %s{json}"

0 // return an integer exit code
```
Expand All @@ -120,7 +114,7 @@ Add a reference to the `Library` project using [dotnet add reference](../../core
dotnet add src/App/App.fsproj reference src/Library/Library.fsproj
```

Add the `App` project to the `FSNetCore` solution using the `dotnet sln add` command:
Add the `App` project to the `FSharpSample` solution using the `dotnet sln add` command:

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

```console
Nice command-line arguments! Here's what Json.NET has to say about them:

I used to be Hello but now I'm ""Hello"" thanks to Json.NET!
I used to be World but now I'm ""World"" thanks to Json.NET!
Nice command-line arguments! Here's what System.Text.Json has to say about them:
Input: { args = [|"Hello"; "World"|] year = 2021 }
Output: {"args":["Hello","World"],"year":2021}
```

## Next steps
Expand Down
8 changes: 4 additions & 4 deletions docs/fsharp/get-started/get-started-visual-studio.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: Get started with F# in Visual Studio
description: Learn how to use F# with Visual Studio.
ms.date: 12/20/2019
ms.date: 10/29/2021
recommendations: false
---
# Get started with F# in Visual Studio

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

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

Expand Down Expand Up @@ -35,10 +35,10 @@ Let's get started by writing some code. Make sure that the `Program.fs` file is
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:

```fsharp
val square: x:int -> int
val square: x: int -> int
```

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`.
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.

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`).

Expand Down
16 changes: 8 additions & 8 deletions docs/fsharp/get-started/get-started-vscode.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Get Started with F# in Visual Studio Code
description: Learn how to use F# with Visual Studio Code and the Ionide plugin suite.
ms.date: 07/23/2021
ms.date: 10/29/2021
---
# Get Started with F# in Visual Studio Code

Expand Down Expand Up @@ -55,7 +55,7 @@ toPigLatin "banana";;
You should see the following result:

```fsharp
val it : string = "ananabay"
val it: string = "ananabay"
```

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

```fsharp
val it : string = "appleyay"
val it: string = "appleyay"
```

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!
Expand All @@ -86,7 +86,7 @@ If the first character in a word starts with a vowel, add "yay" to the end of th
You may have noticed the following in FSI:

```fsharp
val toPigLatin : word:string -> string
val toPigLatin: word: string -> string
```

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.
Expand Down Expand Up @@ -125,10 +125,10 @@ Now, in the `main` function, call your Pig Latin generator function on the argum

```fsharp
[<EntryPoint>]
let main argv =
for name in argv do
let newName = PigLatin.toPigLatin name
printfn "%s in Pig Latin is: %s" name newName
let main args =
for arg in args do
let newArg = PigLatin.toPigLatin arg
printfn "%s in Pig Latin is: %s" arg newArg

0
```
Expand Down
22 changes: 11 additions & 11 deletions docs/fsharp/get-started/get-started-with-visual-studio-for-mac.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: Get started with F# in Visual Studio for Mac
description: Learn how to use F# with Visual Studio for Mac.
ms.date: 07/03/2018
ms.date: 10/29/2021
---
# Get started with F# in Visual Studio for Mac

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).
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).

## Creating a console application

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

## Using F# Interactive

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.
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.

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:

```console
>

val square : x:int -> int
val square: x: int -> int

>
```
Expand All @@ -69,34 +69,34 @@ This shows the same function signature for the `square` function, which you saw

```console
> square 12;;
val it : int = 144
>square 13;;
val it : int = 169
val it: int = 144
> square 13;;
val it: int = 169
```

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:

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

val isOdd : x:int -> bool
val isOdd: x: int -> bool

> isOdd 12;;
val it : bool = false
val it: bool = false
```

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:

```console
> isOdd (square 15);;
val it : bool = true
val it: bool = true
```

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

```console
> 15 |> square |> isOdd;;
val it : bool = true
val it: bool = true
```

The pipe-forward operator, and more, are covered in later tutorials.
Expand Down
2 changes: 1 addition & 1 deletion docs/fsharp/get-started/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Get started with F#
description: Find out how to get started with the F# programming language.
ms.date: 09/12/2020
ms.date: 10/29/2021
---
# Get Started with F\#

Expand Down
2 changes: 1 addition & 1 deletion docs/fsharp/get-started/install-fsharp.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Install F#
description: Learn how to install F# in various different ways.
ms.date: 12/20/2019
ms.date: 10/29/2021
---
# Install F\#

Expand Down
12 changes: 6 additions & 6 deletions docs/fsharp/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ metadata:
ms.topic: landing-page # Required
author: cartermp
ms.author: phcart
ms.date: 07/28/2021
ms.date: 10/29/2021

landingContent:
- title: "Learn to program in F#"
Expand Down Expand Up @@ -53,12 +53,12 @@ landingContent:
url: style-guide/conventions.md
- linkListType: tutorial
links:
- text: "Introduction to Functional Programming in F#"
url: introduction-to-functional-programming/index.md
- text: "First-class functions"
url: introduction-to-functional-programming/first-class-functions.md
- text: "Functional programming concepts in F#"
url: tutorials/functional-programming-concepts.md
- text: "Using Functions in F#"
url: tutorials/using-functions.md
- text: "Async programming in F#"
url: tutorials/asynchronous-and-concurrent-programming/async.md
url: tutorials/async.md
- text: "Type providers"
url: tutorials/type-providers/index.md

Expand Down
16 changes: 16 additions & 0 deletions docs/fsharp/language-reference/active-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,22 @@ Note however that only single-case active patterns can be parameterized.

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

## Struct Representations for Partial Active Patterns

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:

```fsharp
open System

[<return: Struct>]
let (|Int|_|) str =
match Int32.TryParse(str) with
| (true, n) -> ValueSome n
| _ -> ValueNone
```

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).

## See also

- [F# Language Reference](index.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/fsharp/language-reference/anonymous-records.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ It is possible to use a .NET API that requires the use of [C# anonymous types](.
open System.Linq

let names = [ "Ana"; "Felipe"; "Emilia"]
let nameGrouping = names.Select(fun n -> {| Name = n; FirstLetter = n.[0] |})
let nameGrouping = names.Select(fun n -> {| Name = n; FirstLetter = n[0] |})
for ng in nameGrouping do
printfn $"{ng.Name} has first letter {ng.FirstLetter}"
```
Expand Down
Loading