concept void in category .net

appears as: void, void, voids
Concurrency in .NET

This is an excerpt from Manning's book Concurrency in .NET.

It’s common, in imperative programming languages such as C#, to define methods and delegates that don’t return values (void), such as the Parallel.Invoke method. This method’s signature prevents compositionality. Two functions can compose when the output of a function matches the input of the other function.

In function-first programming languages such as F#, every function has a return value, including the case of the unit type, which is comparable to a void but is treated as a value, conceptually not much different from a Boolean or integer.

unit is the type of any expression that lacks any other specific value. Think of functions used for printing to the screen. There’s nothing specific that needs to be returned, and therefore functions may return unit so that the code is still valid. This is the F# equivalent of C#’s void. The reason F# doesn’t use void is that every valid piece of code has a return type, whereas void is the absence of a return. Rather than the concept of void, a functional programmer thinks of unit. In F#, the unit type is written as (). This design enables function composition.

In principle, it isn’t required for a programming language to support methods with return values. But a method without a defined output (void) suggests that the function performs some side effect, which makes it difficult to run tasks in parallel.