Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
File renamed without changes.
1 change: 0 additions & 1 deletion _snippets/oop.md → _snippets/10 oop.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ code: |

F# is **functional first** and **immutable by default**, but it also provides pragmatic support for object programming.
<!--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
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
---
order: 15
order: 12
title: SequenceExpressions.fs
excerpt_separator: <!--more-->
code: |
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"
| _ -> n.ToString()
if n % 15 = 0 then "fizzbuzz"
elif n % 3 = 0 then "fizz"
elif n % 5 = 0 then "buzz"
else n.ToString()

// Tail recursion makes this as efficient as a "while" loop
yield! fizzBuzzSeq (n + 1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
order: 16
order: 13
title: AsyncExpressions.fs
excerpt_separator: <!--more-->
code: |
Expand All @@ -20,7 +20,7 @@ code: |
return $"Validation error: {msg}"
}

processPersonAsync { Name = "Snowdrop"; Age = 13}
processPersonAsync { Name = "Snowdrop"; Age = 13 }
|> Async.RunSynchronously
---
## Async Programming made Easy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
order: 17
order: 14
title: ComputationExpressions.fs
excerpt_separator: <!--more-->
code: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
order: 19
order: 15
title: UnitsOfMeasure.fs
excerpt_separator: <!--more-->
code: |
Expand Down
6 changes: 3 additions & 3 deletions _snippets/typeproviders.md → _snippets/16 type providers.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
order: 14
order: 16
title: TypeProviders.fs
excerpt_separator: <!--more-->
code: |
open FSharp.Data
open FSharp.Data // dotnet package add FSharp.Data

type PeopleDB = CsvProvider<"people.csv">

Expand All @@ -12,7 +12,7 @@ code: |

for person in people.Rows do
// Access the CSV fields with intellisense and type safety!
printfn $"Name: %s{person.Name}, Id: %i{person.Id}"
printfn $"Name: {person.Name: string}, Id: {person.Id: int}"
---
## Type-Safe, Integrated Data

Expand Down
45 changes: 45 additions & 0 deletions _snippets/21 ecosystems.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
order: 21
title: Ecosystems.fs
excerpt_separator: <!--more-->
code: |
// JavaScript Example: Image processing
open Fable.Core
open Fable.Core.JS
// Read documentation, then define the JavaScript type
type [<Import("Image", "image-js")>] Image = // npm install image-js
static member load(path: string): Promise<Image> = jsNative
member _.flipX(): Image = jsNative
member _.flipY(): Image = jsNative
[<ParamObject>] member _.resize(?width: float, ?height: float): Image = jsNative
member _.save(path: string): Promise<unit> = jsNative
promise {
let! image = Image.load "input.png"
let image = image.resize(width=300, height=200).flipX().flipY()
do! image.save "output.jpg"
} |> _.catch(fun x -> console.error x) |> ignore

// .NET Example: Image processing
// C# types have seamless integration with F#.
open SixLabors.ImageSharp // dotnet package add 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"

// Code sharing Example: The same code works across JavaScript and .NET
open System.Text.RegularExpressions // Specific System types are usable anywhere.
let input = "Emails: user1@test.com, user2@domain.org, invalid-email"
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}" // user1@test.com and user2@domain.org
---
## Full access to ecosystems of libraries

F# has full integration with ecosystems of JavaScript and .NET libraries and frameworks.
Anything written in JavaScript or C# can be used from F# and vice versa.
<!--more-->
- **JavaScript** is the universal language of web development. It encompasses [Web](https://developer.mozilla.org/en-US/docs/Web/JavaScript), [Mobile](https://reactnative.dev/), [Desktop](https://www.electronjs.org/), [Cloud](https://nodejs.org/), [Microservices](https://nestjs.com/), [Artificial Intelligence](https://www.tensorflow.org/js), [Game Development](https://phaser.io/) and [Internet of Things](https://johnny-five.io/).
- **.NET** is Microsoft’s enterprise-grade platform for scalable applications. It also encompasses **[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)**.
- [**npm packages**](https://www.npmjs.com/package/image-js) or [**NuGet packages**](https://www.nuget.org) can be accessed from F#, reusing existing packages to suit your needs.
- **Incremental adoption** is possbile by mixing Javascript or C# with F#.
5 changes: 3 additions & 2 deletions _snippets/fable.md → _snippets/22 fable.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
order: 12
order: 22
title: WebApps.fs
excerpt_separator: <!--more-->
code: |
Expand Down Expand Up @@ -32,7 +32,8 @@ code: |
---
## 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.
<!--more-->
- **Type-safe DOM manipulation** catches errors at compile time, not runtime
- **Seamless React integration** with hooks and modern patterns
Expand Down
47 changes: 47 additions & 0 deletions _snippets/ecosystem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
order: 1
title: DotNet.fs
excerpt_separator: <!--more-->
code: |
// JavaScript Example: Image processing
open Fable.Core
open Fable.Core.JS
// Read documentation, then define the JavaScript type
type [<Import("Image", "image-js")>] Image = // npm install image-js
static member load(path: string): Promise<Image> = jsNative
member _.flipX(): Image = jsNative
member _.flipY(): Image = jsNative
[<ParamObject>] member _.resize(?width: float, ?height: float): Image = jsNative
member _.save(path: string): Promise<unit> = jsNative
(promise {
let! image = Image.load "input.png"
let image = image.resize(width=300, height=200).flipX().flipY()
do! image.save "output.jpg"
}).catch(fun x -> console.error x) |> ignore

// .NET Example: Image processing
// C# types have seamless integration with F#.
open SixLabors.ImageSharp // dotnet package add SixLabors.ImageSharp
open SixLabors.ImageSharp.Processing
use image = Image.Load "input.png" // .NET types are integrated seamlessly.
image.Mutate(_.Resize(300, 200).Flip(FlipMode.Horizontal ||| FlipMode.Vertical) >> ignore)
image.Save "output.jpg"

// Code sharing Example: The same code works across JavaScript and .NET
open System.Text.RegularExpressions // Specific System types are usable anywhere.
let input = "Emails: user1@test.com, user2@domain.org, invalid-email"
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}" // user1@test.com and user2@domain.org
---

## Full access to ecosystems of libraries

F# has full integration with ecosystems of JavaScript and Microsoft .NET libraries and frameworks.
Anything written in JavaScript or C# can be used from F# and vice versa.
<!--more-->
- **JavaScript** is the universal language of web development. It encompasses [Web](https://developer.mozilla.org/en-US/docs/Web/JavaScript), [Mobile](https://reactnative.dev/), [Desktop](https://www.electronjs.org/), [Cloud](https://nodejs.org/), [Microservices](https://nestjs.com/), [Artificial Intelligence](https://www.tensorflow.org/js), [Game Development](https://phaser.io/) and [Internet of Things](https://johnny-five.io/).
- **.NET** is Microsoft’s enterprise-grade platform for scalable applications. It also encompasses **[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)**.
- [**npm packages**](https://www.npmjs.com/package/image-js) or [**NuGet packages**](https://www.nuget.org) can be accessed from F#, reusing existing packages to suit your needs.
- **Synergy** is achieved when F# is used for web development both on the front end (JavaScript) and back end (.NET), sharing essential business logic.
- **Incremental adoption** is possible by mixing Javascript or C# with F#.