Skip to content

Include a snippet on the power of .NET #1005

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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
2 changes: 1 addition & 1 deletion _snippets/async_expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
return $"Validation error: {msg}"
}

processPersonAsync { Name = "Snowdrop"; Age = 13}
processPersonAsync { Name = "Snowdrop"; Age = 13 }
|> Async.RunSynchronously
---
## Async Programming made Easy

F# async expressions provide a powerful way to handle asynchronous programming, making it more readable and maintainable. They allow you to write non-blocking code that looks like synchronous code, which is particularly useful for I/O-bound operations.

Check failure on line 28 in _snippets/async_expressions.md

View workflow job for this annotation

GitHub Actions / lint

Line length

_snippets/async_expressions.md:28:101 MD013/line-length Line length [Expected: 100; Actual: 252] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md013.md
<!--more-->
- **Async expressions** provide a clean syntax for defining asynchronous workflows
- **Integration with existing libraries** makes it easy to use async expressions with other F# features
Expand Down
27 changes: 27 additions & 0 deletions _snippets/dotnet_ecosystem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
order: 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this should be so high in the order

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the current order:

  • Concise like Python (HelloWorld.fs)
    • Concise syntax
    • Simple lists
    • String interpolation
    • Pipeline operator
  • Objects Made Simple (OOP.fs)
    • Seamless .NET integration
    • Rich interface system
    • Object expressions
    • Automatic property generation
    • Type extensions

If .NET was to be expanded on to show all the possibilities of the ecosystem, logically it would be placed in between Concise like Python and Objects Made Simple. It's originally the first bullet point of Objects Made Simple, after all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do agree that perhaps everything related to interop should be placed next to the Fable sample though.

title: DotNet.fs
excerpt_separator: <!--more-->
code: |
// Example: Extracting information from text with regular expressions
open System.Text.RegularExpressions
let input = "Emails: [email protected], [email protected], invalid-email"

Check failure on line 8 in _snippets/dotnet_ecosystem.md

View workflow job for this annotation

GitHub Actions / lint

Bare URL used

_snippets/dotnet_ecosystem.md:8:42 MD034/no-bare-urls Bare URL used [Context: "[email protected]"] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md034.md

Check failure on line 8 in _snippets/dotnet_ecosystem.md

View workflow job for this annotation

GitHub Actions / lint

Bare URL used

_snippets/dotnet_ecosystem.md:8:26 MD034/no-bare-urls Bare URL used [Context: "[email protected]"] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md034.md
let pattern = @"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b"
for matched in Regex.Matches(input, pattern) do
printfn $"Found email: {matched.Value}" // [email protected] and [email protected]

Check failure on line 11 in _snippets/dotnet_ecosystem.md

View workflow job for this annotation

GitHub Actions / lint

Bare URL used

_snippets/dotnet_ecosystem.md:11:71 MD034/no-bare-urls Bare URL used [Context: "[email protected]"] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md034.md

Check failure on line 11 in _snippets/dotnet_ecosystem.md

View workflow job for this annotation

GitHub Actions / lint

Bare URL used

_snippets/dotnet_ecosystem.md:11:52 MD034/no-bare-urls Bare URL used [Context: "[email protected]"] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md034.md

// Example: Image processing
open SixLabors.ImageSharp // NuGet package: SixLabors.ImageSharp
open SixLabors.ImageSharp.Processing
use image = Image.Load "input.png"
image.Mutate(_.Resize(300, 200).Flip(FlipMode.Horizontal ||| FlipMode.Vertical) >> ignore)
image.Save "output.jpg"
---

## Full access to .NET ecosystem

F# has seamless .NET integration which lets you work with existing .NET libraries and frameworks. Anything written in C# can be used from F# and vice versa.

Check failure on line 23 in _snippets/dotnet_ecosystem.md

View workflow job for this annotation

GitHub Actions / lint

Line length

_snippets/dotnet_ecosystem.md:23:101 MD013/line-length Line length [Expected: 100; Actual: 156] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md013.md
<!--more-->
- **[Web](https://dotnet.microsoft.com/en-us/apps/aspnet), [Mobile](https://dotnet.microsoft.com/en-us/apps/maui), [Desktop](https://dotnet.microsoft.com/en-us/apps/desktop), [Cloud](https://dotnet.microsoft.com/en-us/apps/cloud), [Microservices](https://dotnet.microsoft.com/en-us/apps/aspnet/microservices), [Artificial Intelligence](https://dotnet.microsoft.com/en-us/apps/ai), [Game Development](https://dotnet.microsoft.com/en-us/apps/games), and [Internet of Things](https://dotnet.microsoft.com/en-us/apps/iot)** frameworks are ready to be used.

Check failure on line 25 in _snippets/dotnet_ecosystem.md

View workflow job for this annotation

GitHub Actions / lint

Line length

_snippets/dotnet_ecosystem.md:25:101 MD013/line-length Line length [Expected: 100; Actual: 552] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md013.md
- [**NuGet packages**](https://www.nuget.org), all hundreds of thousands of them, reduce your code complexity.
- **Mixing C# and F#** in the same solution is possible for incremental adoption.
2 changes: 1 addition & 1 deletion _snippets/fable.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
---
## F# for JavaScript and the Full Stack

F# is for both client and server. With [F# web technologies]({{ '/use/web-apps/' | relative_url }}), you can target JavaScript environments directly. This means you can use F# to build web applications, mobile apps, and even serverless functions that run in the cloud.
F# is for both client and server. With [F# web technologies]({{ '/use/web-apps/' | relative_url }}), you can target JavaScript environments directly without including the rest of .NET. This means you can use F# across both frontend and backend to build web applications, mobile apps, and even serverless functions that run in the cloud.

Check failure on line 35 in _snippets/fable.md

View workflow job for this annotation

GitHub Actions / lint

Line length

_snippets/fable.md:35:101 MD013/line-length Line length [Expected: 100; Actual: 336] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md013.md
<!--more-->
- **Type-safe DOM manipulation** catches errors at compile time, not runtime
- **Seamless React integration** with hooks and modern patterns
- **Full npm ecosystem access** with clean TypeScript-like interop
- **Simplified async programming** with F#'s computation expressions for promises

F# brings its powerful type system and immutability to frontend development, eliminating common JavaScript bugs while maintaining full access to the JavaScript ecosystem.

Check failure on line 42 in _snippets/fable.md

View workflow job for this annotation

GitHub Actions / lint

Line length

_snippets/fable.md:42:101 MD013/line-length Line length [Expected: 100; Actual: 170] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md013.md
1 change: 0 additions & 1 deletion _snippets/oop.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@
---
## Objects Made Simple

F# is **functional first** and **immutable by default**, but it also provides pragmatic support for object programming.

Check failure on line 43 in _snippets/oop.md

View workflow job for this annotation

GitHub Actions / lint

Line length

_snippets/oop.md:43:101 MD013/line-length Line length [Expected: 100; Actual: 119] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md013.md
<!--more-->
- **Seamless .NET integration** lets you work with existing .NET libraries and frameworks
- **Rich interface system** allows you to define clear contracts for your components
- **Object expressions** provide lightweight implementation of interfaces without defining full classes
- **Concise member syntax** keeps methods and properties clean and readable
Expand Down
8 changes: 5 additions & 3 deletions _snippets/sequence_expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ order: 15
title: SequenceExpressions.fs
excerpt_separator: <!--more-->
code: |
// This is an active pattern. It allows customized pattern matching.
let (|Divides|_|) divisor x = x % divisor = 0
let rec fizzBuzzSeq n = seq {
match n with
| x when x % 15 = 0 -> "fizzbuzz"
| x when x % 3 = 0 -> "fizz"
| x when x % 5 = 0 -> "buzz"
| Divides 15 -> "fizzbuzz"
| Divides 3 -> "fizz"
| Divides 5 -> "buzz"
| _ -> n.ToString()

// Tail recursion makes this as efficient as a "while" loop
Expand Down
2 changes: 1 addition & 1 deletion _snippets/typeproviders.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ order: 14
title: TypeProviders.fs
excerpt_separator: <!--more-->
code: |
open FSharp.Data
open FSharp.Data // NuGet package: FSharp.Data

type PeopleDB = CsvProvider<"people.csv">

Expand Down