Dixin's Blog
Microsoft Most Valuable Professional (CodingOnWheels.com) & Photographer (PicturesOnWheels.com). Code examples: GitHub.com/Dixin/Blog.

C# Functional Programming InDepth (14) Asynchronous Function
Asynchronous function can improve the responsiveness and scalability of the application and service. C# 5.0 introduces asynchronous function to greatly simplify the async programming model.

Setup and use CUDA and TensorFlow in Windows Subsystem for Linux 2
Table of contents
 Install Windows preview
 Install WSL 2 preview
 Install Nvidia driver preview and CUDA toolkit
 Run CUDA sample application
 Install Docker and Nvidia container toolkit
 Run CUDA containers
 Troubleshoot
 Run WSL + CUDA + Docker + Jupyter + TensorFlow
 Encoding and decoding video with GPU in WSL?
GPU support is the most requested feature in Windows Subsystem for Linux (WSL). It is available in WSL 2.0 through Windows Insiders program. And Nvidia CUDA is supported. The following diagram shows the WDDM model supporting CUDA user mode driver running inside Linux guest:
So the popular Linux AI frameworks like TensorFlow, PyTorch, etc. can work with WSL with CUDA acceleration:
This article walks through the installation of Windows, WSL, CUDA in WSL, and Docker in WSL.
Install Windows preview
First, you must enable “Optional diagnostic data”, otherwise Windows cannot join Windows Insiders.
Then, join Windows Insiders program with Microsoft account (an account can be created if you don’t have one: https://insider.windows.com/). The channel must be Dev:
Then run Windows Update. It will download the pre=release installer. Windows will restart and reinstall.
Install WSL 2 preview
In Windows, make sure the following Windows features are enabled:
 WSL:
dism.exe /online /enablefeature /featurename:MicrosoftWindowsSubsystemLinux /all /norestart  Virtual machine platform:
dism.exe /online /enablefeature /featurename:VirtualMachinePlatform /all /norestart
Now restart Windows, then Windows will have WSL and the wsl command line tool. Run Windows Update again to get the latest WSL 2. When this is done, in the update history, it must show 4.19.121 or later:
Then manually install this patch: https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi. And then run the following command as administrator to update the kernel to the latest version:
C:\WINDOWS\system32>wsl update
Checking for updates...
Downloading updates...
Installing updates...
This change will take effect on the next full restart of WSL. To force a restart, please run 'wsl shutdown'.
Kernel version: 5.4.72 
Update code font from Consolas to Cascadia Code with ligature
A decade ago, I blogged that I switched my code font from Courier New to Consolas. They are both monospaced. The difference is:
 Courier New is an old font introduced in Windows 3.1.
 Consolas is introduced with Windows Vista/Office 2007/Visual Studio 2010. It always uses ClearType, which is designed for LCD screens and other flat panels which arrange their pixels in vertical stripes of red, green and blue.

Installing SQL Server 2017/2019 LocalDB and resolve the engine versioning problem
SQL Server LocalDB is a minimal SQL Server database engine, it can be installed and used with zero configuration.

Understanding (all) JavaScript module formats and tools
When you build an application with JavaScript, you always want to modularize your code. However, JavaScript language was initially invented for simple form manipulation, with no builtin features like module or namespace. In years, tons of technologies are invented to modularize JavaScript. This article discusses all mainstream terms, patterns, libraries, syntax, and tools for JavaScript modules.

Port Microsoft Concurrency Visualizer SDK to .NET Standard and NuGet
I uploaded a NuGet package of Microsoft Concurrency Visualizer SDK: ConcurrencyVisualizer. Microsoft Concurrency Visualizer is an extension tool for Visual Studio. It is a great tool for performance profiling and multithreading execution visualization. It also has
a SDK library to be invoked by code and draw markers and spans in the timeline. I used it to visualize sequential LINQ and Parallel LINQ (PLINQ) execution in my Functional Programming and LINQ tutorials. For example, array.Where(…).Select(…) sequential LINQ query and array.AsParallel().Where(…).Select(…) Parallel LINQ query can be visualized as following spans: 
TransientFaultHandling.Core: Retry library for .NET Core/.NET Standard
TransientFaultHandling.Core is retry library for transient error handling. It is ported from Microsoft Enterprise Library’s TransientFaultHandling library, a library widely used with .NET Framework. The retry pattern APIs are ported to .NET Core/.NET Standard, with outdated configuration API updated, and new retry APIs added for convenience.
Introduction
With this library, the old code of retry logic based on Microsoft Enterprise Library can be ported to .NET Core/.NET Standard without modification:

EntityFramework.Functions: Code First Functions for Entity Framework
EntityFramework.Functions library implements Entity Framework code first support for:

Expert Functional Programming and LINQ via C#

Category Theory via C# (8) Advanced LINQ to Monads
Monad is a powerful structure, with the LINQ support in C# language, monad enables chaining operations to build fluent workflow, which can be pure. With these features, monad can be used to manage I/O, state changes, exception handling, shared environment, logging/tracing, and continuation, etc., in the functional paradigm.

Category Theory via C# (7) Monad and LINQ to Monads
As fore mentioned endofunctor category can be monoidal (the entire category. Actually, an endofunctor In the endofunctor category can be monoidal too. This kind of endofunctor is called monad. Monad is another important algebraic structure in category theory and LINQ. Formally, monad is an endofunctor equipped with 2 natural transformations:

Category Theory via C# (6) Monoidal Functor and Applicative Functor
Given monoidal categories (C, ⊗, I_{C}) and (D, ⊛, I_{D}), a strong lax monoidal functor is a functor F: C → D equipped with:

Category Theory via C# (5) Bifunctor
A functor is the mapping from 1 object to another object, with a “Select” ability to map 1 morphism to another morphism. A bifunctor (binary functor), as the name implies, is the mapping from 2 objects and from 2 morphisms. Giving category C, D and E, bifunctor F from category C, D to E is a structurepreserving morphism from C, D to E, denoted F: C × D → E:

Category Theory via C# (4) Natural Transformation
If F: C → D and G: C → D are both functors from categories C to category D, the mapping from F to G is called natural transformation and denoted α: F ⇒ G. α: F ⇒ G is actually family of morphisms from F to G, For each object X in category C, there is a specific morphism α_{X}: F(X) → G(X) in category D, called the component of α at X. For each morphism m: X → Y in category C and 2 functors F: C → D, G: C → D, there is a naturality square in D:

Category Theory via C# (3) Functor and LINQ to Functors
In category theory, functor is a mapping from category to category. Giving category C and D, functor F from category C to D is a structurepreserving morphism from C to D, denoted F: C → D:

Category Theory via C# (2) Monoid
Monoid is an important algebraic structure in category theory. A monoid M is a set M equipped with a binary operation ⊙ and a special element I, denoted 3tuple (M, ⊙, I), where

Category Theory via C# (1) Fundamentals
Category theory is a theoretical framework to describe abstract structures and relations in mathematics, first introduced by Samuel Eilenberg and Saunders Mac Lane in 1940s. It examines mathematical concepts and properties in an abstract way, by formalizing them as collections of items and their relations. Category theory is abstract, and called "general abstract nonsense" by Norman Steenrod; It is also general, therefore widely applied in many areas in mathematics, physics, and computer science, etc. For programming, category theory is the algebraic theory of types and functions, and also the rationale and foundation of LINQ and any functional programming. This chapter discusses category theory and its important concepts, including category, morphism, natural transform, monoid, functor, and monad, etc. These general abstract concepts will be demonstrated with intuitive diagrams and specific C# and LINQ examples. These knowledge also helps building a deep understanding of functional programming in C# or other languages, since any language with types and functions is a categorytheoretic structure.

Lambda Calculus via C# (8) Undecidability of Equivalence
All the previous parts demonstrated what lambda calculus can do – defining functions to model the computing, applying functions to execute the computing, implementing recursion, encoding data types and data structures, etc. Lambda calculus is a powerful tool, and it is Turing complete. This part discuss some interesting problem that cannot be done with lambda calculus – asserting whether 2 lambda expressions are equivalent.

Lambda Calculus via C# (7) Fixed Point Combinator and Recursion
p is the fixed point (aka invariant point) of function f if and only if:

Lambda Calculus via C# (6) Combinatory Logic
In lambda calculus, the primitive is function, which can have free variables and bound variables. Combinatory logic was introduced by Moses Schönfinkel and Haskell Curry in 1920s. It is equivalent variant lambda calculus, with combinator as primitive. A combinator can be viewed as an expression with no free variables in its body.