Archives
-
Category Theory via C# (23) Performance
In functional programming, there are many powerful tools and patterns, like lambda expression, purity, deferred execution, immutability, fluent LINQ query composition, … But everything has a cost. As Alan Perlis said:
-
Category Theory via C# (22) More Monad: Continuation Monad
In C#, callback is frequently used. For example, a very simple Add function, without asynchrony:
-
Category Theory via C# (21) More Monad: Writer< , > Monad
Unlike the Reader< , > monad, the Writer< , > monad output contents with a sequence of functions:
-
Category Theory via C# (20) More Monad: Reader< , > Monad
Sometimes there are functions work with a shared environment. Typical examples are:
-
Category Theory via C# (19) More Monad: State< , > Monad
State machine (or finite state machine) represents a abstract machine with one state or a number of state. C# use state machine a lot. For example:
-
Category Theory via C# (18) More Monad: IO<> Monad
As mentioned in a previous part, in purely functional programming, functions cannot have side effects. For example, when defining LINQ queries, laziness and purity are expected. So, how should the impure actions be managed in purely functional programming or LINQ? For example:
-
Category Theory via C# (17) Monad-like Tuple<>, Task<>, IQueryable<> And IQbservable<>
Theoretically, Tuple<> should be counted as the Id<> monad. However, it is lack of laziness. In the context of C# and LINQ, it is only monad-like.
-
Category Theory via C# (16) More Monads: Lazy<>, Func<>, Nullable<>, ParallelQuery<> And IObservale<>
Again, Lazy<> is the simplest monad, it is just the lazy version of Tuple<>, and should be considered as the Id<> monad. This is the implementation of its SelectMany:
-
Category Theory via C# (15) IEnumerable<> Monad And LINQ: SelectMany For All
Previous part introduced SelectMany for monad IEnumerable<>. Actually SelectMany is more than meets the eye, and can be used to implement other LINQ queries.
-
Category Theory via C# (14) Monad And IEnumerable<>
A previous part showed endofunctor category is a monoid (the entire category itself). An endofunctor In the endofunctor category can be monoid too. This kind of endofunctor is called monad. Formally, monad is an endofunctor of category C, equipped with 2 natural transformations:
-
Category Theory via C# (13) Monoidal Functor-like Tuple<> And Task<>
Theoretically, Tuple<> should be counted as the Id<> monoidal functor. However, as previously mentioned, it is lack of laziness.
-
Category Theory via C# (12) More Monoidal Functors: Lazy<>, Func<> And Nullable<>
Lazy<> should be the simplest monoid functor - it is just the lazy version of Tuple<>. And in these posts it will be considered as the Id<> monoidal functor.
-
Category Theory via C# (11) Monoidal Functor And IEnumerable<>
Given monoidal categories (C, ⊗, IC) and (D, ⊛, ID), a monoidal functor (or lax monoidal functors) is a functor F: C → D equipped with:
-
Category Theory via C# (10) Monoidal Category
A previous part demonstrated endofunctor category is monoidal. Now with the help of bifunctor, the general abstract monoidal category can be defined. A monoidal category is a category C equipped with:
-
Category Theory via C# (9) Bifunctor
As discussed in all the previous functor parts, a functor is a wrapper of a object with a “Select” ability to preserve a morphism to another‘
-
Category Theory via C# (8) Functor Category
Given 2 categories C and D, functors C → D forms a functor category, denoted DC:
-
Category Theory via C# (7) Natural Transformation
If F: C -> D and G: C -> D are both functors from categories C to category D, a mapping can be constructed between F and G, called natural transformation and denoted η : F ⇒ G.
-
Category Theory via C# (6) Functor-like Tuple<>, Task<> And IQueryable<>
Tuple<> looks like the simplest functor by just wrapping a value. It is most close to the Identity functor of Haskell. Its Select functions are:
-
Category Theory via C# (5) More Functors: Lazy<>, Func<> And Nullable<>
A simple functor in DotNet category is Lazy<>. Its Select functions can be easily implemented:
-
Category Theory via C# (4) Functor And IEnumerable<>
A functor F: C → D is a structure-preserving mapping from category C to category D:
-
Category Theory via C# (3) Monoid as Category
An individual monoid (T, ⊙, I) can be a category M:
-
Category Theory via C# (2) Monoid
A monoid, denoted a 3-tuple (M, ⊙, I), is a set M with
-
Category Theory via C# (1) Fundamentals - Category, Object And Morphism
This post and the following posts will introduce category theory and its important concepts via C# and LINQ, including functor, applicative functor, monoid, monad, etc. Categories were first introduced by Samuel Eilenberg and Saunders Mac Lane in 1942–45. It might be tedious, as Wikipedia pointed: