Page 20 - MSDN Magazine, September 2019
P. 20

F#
Do It All with F#
on .NET Core
Phillip Carter
F# is the functional programming language for .NET (bit.ly/2y4PeQG). It’s cross-platform and, like all of .NET, it’s open source (github.com/dotnet/fsharp). At Microsoft, we’re huge fans of F# because it brings functional programming to .NET. For those who aren’t familiar with the concept, the functional programming par- adigm is one that emphasizes certain approaches:
• Functions as the primary constructs used to operate on data • Expressions instead of statements
• Immutable values over variables
• Declarative programming over imperative programming
This means that F# brings some great features to .NET:
• Functions that are first-class (they can be passed as values
to and returned from other functions)
• Lightweight syntax that emphasizes expressions and values,
not statements
• Built-in immutability and non-null types
• Rich data types and advanced pattern matching techniques
Typical F# code often ends up looking like what’s shown in Figure 1.
Beyond these core features, F# can also interop with the entirety of .NET, and has full support for objects, interfaces and so forth. More advanced F# programming techniques often involve subtly combining object-oriented (OO) features with functional code, but without sacrificing the functional programming paradigm.
In addition, F# has lots of unique features that people love, such as Computation Expressions, Units of Measure, and powerful types such as Records and Discriminated Unions. See the F# Language Reference at bit.ly/2JSnipy for more information. F# also encourages a style of programming that tends toward safety and correctness: Many F# developers have turned to it after significant experience with other languages that don’t emphasize safety and correctness as much. It has influenced a lot of the recent work that went into C#, such as async, tuples, pattern matching, and the forthcoming nullable reference types feature set.
At Microsoft, we’re huge fans of F# because it brings functional programming to .NET.
F# also has a vibrant community that loves to push the bound- aries of .NET and create incredible open source components. The community is highly innovative and incredibly valuable to .NET, pioneering UI libraries, data processing libraries, testing method- ologies, Web services and more for .NET!
The abundance of features and the vibrant community of enthusiastic developers have led many people to dive into F# both
This article discusses:
• Getting started with F# using the .NET CLI
• Building a Web app with F#
• Using Span<'T> to enhance performance on .NET Core
Technologies discussed:
F#, .NET Core, Giraffe, ASP.NET Core
Code download available at:
bit.ly/2Z21yNq
16 msdn magazine


































































































   18   19   20   21   22