From 63700bf6d9cfac74dcacaec9beea9ea4dad74992 Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Sun, 25 May 2025 06:19:30 +0800 Subject: [PATCH 01/17] Include a snippet on the power of .NET --- _snippets/async_expressions.md | 2 +- _snippets/dotnet_ecosystem.md | 26 ++++++++++++++++++++++++++ _snippets/fable.md | 2 +- _snippets/oop.md | 1 - _snippets/sequence_expressions.md | 7 ++++--- _snippets/typeproviders.md | 2 +- 6 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 _snippets/dotnet_ecosystem.md diff --git a/_snippets/async_expressions.md b/_snippets/async_expressions.md index c14854d6..0b8fdd27 100644 --- a/_snippets/async_expressions.md +++ b/_snippets/async_expressions.md @@ -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 diff --git a/_snippets/dotnet_ecosystem.md b/_snippets/dotnet_ecosystem.md new file mode 100644 index 00000000..811cb90d --- /dev/null +++ b/_snippets/dotnet_ecosystem.md @@ -0,0 +1,26 @@ +--- +order: 1 +title: DotNet.fs +excerpt_separator: +code: | + // Example: Extracting information from text with regular expressions + open System.Text.RegularExpressions + 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 + + // 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. + +- **[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. +- [**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. \ No newline at end of file diff --git a/_snippets/fable.md b/_snippets/fable.md index 447dfb30..15b347bf 100644 --- a/_snippets/fable.md +++ b/_snippets/fable.md @@ -32,7 +32,7 @@ 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. - **Type-safe DOM manipulation** catches errors at compile time, not runtime - **Seamless React integration** with hooks and modern patterns diff --git a/_snippets/oop.md b/_snippets/oop.md index be1ec08c..b9feb58e 100644 --- a/_snippets/oop.md +++ b/_snippets/oop.md @@ -42,7 +42,6 @@ code: | F# is **functional first** and **immutable by default**, but it also provides pragmatic support for object programming. -- **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 diff --git a/_snippets/sequence_expressions.md b/_snippets/sequence_expressions.md index 90916d95..521f473d 100644 --- a/_snippets/sequence_expressions.md +++ b/_snippets/sequence_expressions.md @@ -3,11 +3,12 @@ order: 15 title: SequenceExpressions.fs excerpt_separator: code: | + let (|Divides|_|) divisor x = x % divisor = 0 // This is an active pattern. It allows customized pattern matching. 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 diff --git a/_snippets/typeproviders.md b/_snippets/typeproviders.md index b48e2674..c79c95ae 100644 --- a/_snippets/typeproviders.md +++ b/_snippets/typeproviders.md @@ -3,7 +3,7 @@ order: 14 title: TypeProviders.fs excerpt_separator: code: | - open FSharp.Data + open FSharp.Data // NuGet package: FSharp.Data type PeopleDB = CsvProvider<"people.csv"> From b7a7f787daf327141360e8042d6d667bdf2ed781 Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Sun, 25 May 2025 06:23:07 +0800 Subject: [PATCH 02/17] Update dotnet_ecosystem.md --- _snippets/dotnet_ecosystem.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_snippets/dotnet_ecosystem.md b/_snippets/dotnet_ecosystem.md index 811cb90d..6a937e0c 100644 --- a/_snippets/dotnet_ecosystem.md +++ b/_snippets/dotnet_ecosystem.md @@ -14,7 +14,7 @@ code: | 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.Mutate(_.Resize(300, 200).Flip(FlipMode.Horizontal ||| FlipMode.Vertical) >> ignore) image.Save "output.jpg" --- ## Full access to .NET ecosystem @@ -23,4 +23,4 @@ F# has seamless .NET integration which lets you work with existing .NET librarie - **[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. - [**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. \ No newline at end of file +- **Mixing C# and F#** in the same solution is possible for incremental adoption. From e4455e28d85277ae34fc2fd4d4303074539620c1 Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Sun, 25 May 2025 06:23:55 +0800 Subject: [PATCH 03/17] Update dotnet_ecosystem.md --- _snippets/dotnet_ecosystem.md | 1 + 1 file changed, 1 insertion(+) diff --git a/_snippets/dotnet_ecosystem.md b/_snippets/dotnet_ecosystem.md index 6a937e0c..fdf73296 100644 --- a/_snippets/dotnet_ecosystem.md +++ b/_snippets/dotnet_ecosystem.md @@ -17,6 +17,7 @@ code: | 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. From 1289bff89ab2a0d5d9906ba40d36e51d76fa18ac Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Sun, 25 May 2025 06:25:14 +0800 Subject: [PATCH 04/17] Update sequence_expressions.md --- _snippets/sequence_expressions.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/_snippets/sequence_expressions.md b/_snippets/sequence_expressions.md index 521f473d..bd5a8ce7 100644 --- a/_snippets/sequence_expressions.md +++ b/_snippets/sequence_expressions.md @@ -3,7 +3,8 @@ order: 15 title: SequenceExpressions.fs excerpt_separator: code: | - let (|Divides|_|) divisor x = x % divisor = 0 // This is an active pattern. It allows customized pattern matching. + // 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 | Divides 15 -> "fizzbuzz" From 2a9b303953821117292dec8f16cd5c0d0c8053c7 Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Sun, 25 May 2025 18:59:26 +0800 Subject: [PATCH 05/17] Focus on the seq expression --- _snippets/sequence_expressions.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/_snippets/sequence_expressions.md b/_snippets/sequence_expressions.md index bd5a8ce7..dab586aa 100644 --- a/_snippets/sequence_expressions.md +++ b/_snippets/sequence_expressions.md @@ -3,14 +3,11 @@ order: 15 title: SequenceExpressions.fs excerpt_separator: 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 - | Divides 15 -> "fizzbuzz" - | Divides 3 -> "fizz" - | Divides 5 -> "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) From 3529707a506c02b6a478645c9ea5e9c3d8a6e5cb Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Wed, 28 May 2025 23:58:30 +0800 Subject: [PATCH 06/17] Javascript or .NET --- _snippets/dotnet_ecosystem.md | 27 -------------------- _snippets/ecosystem.md | 46 +++++++++++++++++++++++++++++++++++ _snippets/fable.md | 3 ++- 3 files changed, 48 insertions(+), 28 deletions(-) delete mode 100644 _snippets/dotnet_ecosystem.md create mode 100644 _snippets/ecosystem.md diff --git a/_snippets/dotnet_ecosystem.md b/_snippets/dotnet_ecosystem.md deleted file mode 100644 index fdf73296..00000000 --- a/_snippets/dotnet_ecosystem.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -order: 1 -title: DotNet.fs -excerpt_separator: -code: | - // Example: Extracting information from text with regular expressions - open System.Text.RegularExpressions - 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 - - // 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. - -- **[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. -- [**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. diff --git a/_snippets/ecosystem.md b/_snippets/ecosystem.md new file mode 100644 index 00000000..c60cd26a --- /dev/null +++ b/_snippets/ecosystem.md @@ -0,0 +1,46 @@ +--- +order: 1 +title: DotNet.fs +excerpt_separator: +code: | + // JavaScript Example: Image processing + open Fable.Core + open Fable.Core.JS + // Read documentation, then define the JavaScript type + type [] Image = // npm install image-js + static member load(path: string): Promise = jsNative + member _.flipX(): Image = jsNative + member _.flipY(): Image = jsNative + [] member _.resize(?width: float, ?height: float): Image = jsNative + member _.save(path: string): Promise = 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. + +- **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#. diff --git a/_snippets/fable.md b/_snippets/fable.md index 15b347bf..39c65de4 100644 --- a/_snippets/fable.md +++ b/_snippets/fable.md @@ -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 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. +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. - **Type-safe DOM manipulation** catches errors at compile time, not runtime - **Seamless React integration** with hooks and modern patterns From 6055e4abe331f1ba751b72b29d4b69a3c2773a81 Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Thu, 29 May 2025 00:00:30 +0800 Subject: [PATCH 07/17] Update ecosystem.md --- _snippets/ecosystem.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_snippets/ecosystem.md b/_snippets/ecosystem.md index c60cd26a..e58c0a50 100644 --- a/_snippets/ecosystem.md +++ b/_snippets/ecosystem.md @@ -1,6 +1,6 @@ --- order: 1 -title: DotNet.fs +title: Ecosystems.fs excerpt_separator: code: | // JavaScript Example: Image processing From 86a9d72a9d8362e8d6fad47921038494861733d8 Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Thu, 29 May 2025 00:00:55 +0800 Subject: [PATCH 08/17] Update ecosystem.md --- _snippets/ecosystem.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_snippets/ecosystem.md b/_snippets/ecosystem.md index e58c0a50..be5076c0 100644 --- a/_snippets/ecosystem.md +++ b/_snippets/ecosystem.md @@ -37,7 +37,7 @@ code: | ## Full access to ecosystems of libraries -F# has full integration with ecosystems of JavaScript and Microsoft .NET libraries and frameworks. +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. - **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/). From fe92e1eb40002671e4c0baf7400c42100bca43ac Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Thu, 29 May 2025 00:03:39 +0800 Subject: [PATCH 09/17] Update ecosystem.md --- _snippets/ecosystem.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/_snippets/ecosystem.md b/_snippets/ecosystem.md index be5076c0..a7d170d7 100644 --- a/_snippets/ecosystem.md +++ b/_snippets/ecosystem.md @@ -33,8 +33,7 @@ code: | 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. From 3d4b3d96b55b9b0e10431a1c58f307ed30bd4761 Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Thu, 29 May 2025 00:04:11 +0800 Subject: [PATCH 10/17] Update typeproviders.md --- _snippets/typeproviders.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_snippets/typeproviders.md b/_snippets/typeproviders.md index c79c95ae..4c1c2120 100644 --- a/_snippets/typeproviders.md +++ b/_snippets/typeproviders.md @@ -3,7 +3,7 @@ order: 14 title: TypeProviders.fs excerpt_separator: code: | - open FSharp.Data // NuGet package: FSharp.Data + open FSharp.Data // dotnet package add FSharp.Data type PeopleDB = CsvProvider<"people.csv"> From 0e802b167b7f8b845f3642035c179db4fe4b839c Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Thu, 29 May 2025 00:12:54 +0800 Subject: [PATCH 11/17] Changed order --- _snippets/async_expressions.md | 2 +- _snippets/computation_expressions.md | 2 +- _snippets/ecosystem.md | 2 +- _snippets/fable.md | 2 +- _snippets/sequence_expressions.md | 2 +- _snippets/typeproviders.md | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/_snippets/async_expressions.md b/_snippets/async_expressions.md index 0b8fdd27..980ec66e 100644 --- a/_snippets/async_expressions.md +++ b/_snippets/async_expressions.md @@ -1,5 +1,5 @@ --- -order: 16 +order: 13 title: AsyncExpressions.fs excerpt_separator: code: | diff --git a/_snippets/computation_expressions.md b/_snippets/computation_expressions.md index 42a728c2..4cc5ebe5 100644 --- a/_snippets/computation_expressions.md +++ b/_snippets/computation_expressions.md @@ -1,5 +1,5 @@ --- -order: 17 +order: 14 title: ComputationExpressions.fs excerpt_separator: code: | diff --git a/_snippets/ecosystem.md b/_snippets/ecosystem.md index a7d170d7..e88fb497 100644 --- a/_snippets/ecosystem.md +++ b/_snippets/ecosystem.md @@ -1,5 +1,5 @@ --- -order: 1 +order: 21 title: Ecosystems.fs excerpt_separator: code: | diff --git a/_snippets/fable.md b/_snippets/fable.md index 39c65de4..d6597b08 100644 --- a/_snippets/fable.md +++ b/_snippets/fable.md @@ -1,5 +1,5 @@ --- -order: 12 +order: 22 title: WebApps.fs excerpt_separator: code: | diff --git a/_snippets/sequence_expressions.md b/_snippets/sequence_expressions.md index dab586aa..4815e073 100644 --- a/_snippets/sequence_expressions.md +++ b/_snippets/sequence_expressions.md @@ -1,5 +1,5 @@ --- -order: 15 +order: 12 title: SequenceExpressions.fs excerpt_separator: code: | diff --git a/_snippets/typeproviders.md b/_snippets/typeproviders.md index 4c1c2120..7066b04b 100644 --- a/_snippets/typeproviders.md +++ b/_snippets/typeproviders.md @@ -1,5 +1,5 @@ --- -order: 14 +order: 15 title: TypeProviders.fs excerpt_separator: code: | From 1983596a8e97fcff30a18587b2479ce15756fa43 Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Thu, 29 May 2025 00:17:34 +0800 Subject: [PATCH 12/17] Reoder again --- _snippets/{helloworld.md => 0 helloworld.md} | 0 _snippets/{oop.md => 10 oop.md} | 0 _snippets/{domain_modelling.md => 11 domain modelling.md} | 0 .../{sequence_expressions.md => 12 sequence expressions.md} | 0 _snippets/{async_expressions.md => 13 async expressions.md} | 0 ...computation_expressions.md => 14 computation expressions.md} | 0 _snippets/{unitsOfMeasure.md => 15 units of measure.md} | 2 +- _snippets/{typeproviders.md => 16 type providers.md} | 2 +- _snippets/{ecosystem.md => 21 ecosystems.md} | 0 _snippets/{fable.md => 22 fable.md} | 0 10 files changed, 2 insertions(+), 2 deletions(-) rename _snippets/{helloworld.md => 0 helloworld.md} (100%) rename _snippets/{oop.md => 10 oop.md} (100%) rename _snippets/{domain_modelling.md => 11 domain modelling.md} (100%) rename _snippets/{sequence_expressions.md => 12 sequence expressions.md} (100%) rename _snippets/{async_expressions.md => 13 async expressions.md} (100%) rename _snippets/{computation_expressions.md => 14 computation expressions.md} (100%) rename _snippets/{unitsOfMeasure.md => 15 units of measure.md} (99%) rename _snippets/{typeproviders.md => 16 type providers.md} (98%) rename _snippets/{ecosystem.md => 21 ecosystems.md} (100%) rename _snippets/{fable.md => 22 fable.md} (100%) diff --git a/_snippets/helloworld.md b/_snippets/0 helloworld.md similarity index 100% rename from _snippets/helloworld.md rename to _snippets/0 helloworld.md diff --git a/_snippets/oop.md b/_snippets/10 oop.md similarity index 100% rename from _snippets/oop.md rename to _snippets/10 oop.md diff --git a/_snippets/domain_modelling.md b/_snippets/11 domain modelling.md similarity index 100% rename from _snippets/domain_modelling.md rename to _snippets/11 domain modelling.md diff --git a/_snippets/sequence_expressions.md b/_snippets/12 sequence expressions.md similarity index 100% rename from _snippets/sequence_expressions.md rename to _snippets/12 sequence expressions.md diff --git a/_snippets/async_expressions.md b/_snippets/13 async expressions.md similarity index 100% rename from _snippets/async_expressions.md rename to _snippets/13 async expressions.md diff --git a/_snippets/computation_expressions.md b/_snippets/14 computation expressions.md similarity index 100% rename from _snippets/computation_expressions.md rename to _snippets/14 computation expressions.md diff --git a/_snippets/unitsOfMeasure.md b/_snippets/15 units of measure.md similarity index 99% rename from _snippets/unitsOfMeasure.md rename to _snippets/15 units of measure.md index f305985c..c241b3f1 100644 --- a/_snippets/unitsOfMeasure.md +++ b/_snippets/15 units of measure.md @@ -1,5 +1,5 @@ --- -order: 19 +order: 15 title: UnitsOfMeasure.fs excerpt_separator: code: | diff --git a/_snippets/typeproviders.md b/_snippets/16 type providers.md similarity index 98% rename from _snippets/typeproviders.md rename to _snippets/16 type providers.md index 7066b04b..70cee390 100644 --- a/_snippets/typeproviders.md +++ b/_snippets/16 type providers.md @@ -1,5 +1,5 @@ --- -order: 15 +order: 16 title: TypeProviders.fs excerpt_separator: code: | diff --git a/_snippets/ecosystem.md b/_snippets/21 ecosystems.md similarity index 100% rename from _snippets/ecosystem.md rename to _snippets/21 ecosystems.md diff --git a/_snippets/fable.md b/_snippets/22 fable.md similarity index 100% rename from _snippets/fable.md rename to _snippets/22 fable.md From a03163b0db6adfb188a95fe0f48e4a444aca1fba Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Thu, 29 May 2025 00:21:41 +0800 Subject: [PATCH 13/17] Update 21 ecosystems.md --- _snippets/21 ecosystems.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_snippets/21 ecosystems.md b/_snippets/21 ecosystems.md index e88fb497..e8b9fdde 100644 --- a/_snippets/21 ecosystems.md +++ b/_snippets/21 ecosystems.md @@ -13,11 +13,11 @@ code: | member _.flipY(): Image = jsNative [] member _.resize(?width: float, ?height: float): Image = jsNative member _.save(path: string): Promise = jsNative - (promise { + 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 + } |> _.catch(fun x -> console.error x) |> ignore // .NET Example: Image processing // C# types have seamless integration with F#. From 609813b8bacc7c286d4c73d1c926242d45277041 Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Thu, 29 May 2025 00:23:12 +0800 Subject: [PATCH 14/17] Update 21 ecosystems.md --- _snippets/21 ecosystems.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_snippets/21 ecosystems.md b/_snippets/21 ecosystems.md index e8b9fdde..e56ac31c 100644 --- a/_snippets/21 ecosystems.md +++ b/_snippets/21 ecosystems.md @@ -23,7 +23,7 @@ code: | // 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. + use image = Image.Load "input.png" image.Mutate(_.Resize(300, 200).Flip(FlipMode.Horizontal ||| FlipMode.Vertical) >> ignore) image.Save "output.jpg" From 9783bbe665e3ac6f166eeea9ec78896ccdf9ea34 Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Thu, 29 May 2025 00:25:43 +0800 Subject: [PATCH 15/17] Update 16 type providers.md --- _snippets/16 type providers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_snippets/16 type providers.md b/_snippets/16 type providers.md index 70cee390..bec73076 100644 --- a/_snippets/16 type providers.md +++ b/_snippets/16 type providers.md @@ -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 From 36ca9ff00884b1b303113b3146f150eac0ea967b Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Thu, 29 May 2025 03:04:17 +0800 Subject: [PATCH 16/17] Fix typo --- _snippets/ecosystem.md | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 _snippets/ecosystem.md diff --git a/_snippets/ecosystem.md b/_snippets/ecosystem.md new file mode 100644 index 00000000..3b4c679b --- /dev/null +++ b/_snippets/ecosystem.md @@ -0,0 +1,46 @@ +--- +order: 1 +title: DotNet.fs +excerpt_separator: +code: | + // JavaScript Example: Image processing + open Fable.Core + open Fable.Core.JS + // Read documentation, then define the JavaScript type + type [] Image = // npm install image-js + static member load(path: string): Promise = jsNative + member _.flipX(): Image = jsNative + member _.flipY(): Image = jsNative + [] member _.resize(?width: float, ?height: float): Image = jsNative + member _.save(path: string): Promise = 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. + +- **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 possible by mixing Javascript or C# with F#. From 9e5fd2d3040d5b808922fce2e6a718f4b493c253 Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Wed, 2 Jul 2025 02:52:09 +0800 Subject: [PATCH 17/17] Update ecosystem.md --- _snippets/ecosystem.md | 1 + 1 file changed, 1 insertion(+) diff --git a/_snippets/ecosystem.md b/_snippets/ecosystem.md index 3b4c679b..c0173995 100644 --- a/_snippets/ecosystem.md +++ b/_snippets/ecosystem.md @@ -43,4 +43,5 @@ Anything written in JavaScript or C# can be used from F# and vice versa. - **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#.