concept functional list in category c#

appears as: functional lists, functional list
Real-World Functional Programming with Examples in F# and C#

This is an excerpt from Manning's book Real-World Functional Programming with Examples in F# and C#.

As already mentioned, functional lists are immutable, so all properties of the class are read only. We’re implementing all of them using C# 3.0 automatic properties, which generate a getter and setter of the property for us, but we’re specifying that the setter should be private, so they can’t be modified from outside. To make the type truly read only, we set the values of the properties only in constructors, so once a list cell is created, none of its properties can change. The fact that there are many different implementation strategies for declaring immutable types demonstrates that immutability is a concept that we can use in different ways and not a language feature. When using automatic properties, we’re losing the checking that the C# compiler can do when we use fields marked using readonly as a trade-off for a more convenient syntax.

3.3.2. Introducing functional lists

Now that we’re more comfortable with the general principle of recursion, we can look at functional lists in some detail. Earlier we mentioned that a list is either empty or composed from an element and another list. This means that we need a special value to represent an empty list, and a way of constructing a list by taking an existing list and prepending an element at the beginning. The first option (an empty list) is sometimes called nil, and the second option produces a cons cell (short for constructed list cell). You can see a sample list constructed using an empty list and cons cells in figure 3.1.