'Properly implement F# Unit in C#
This question is not about C#/F# compatibility as in this one.
I'd like to know the proper way to implement a type like F# Unit in place of using void.
Obviously I'll discard this result and I'll not expose this type to the outside world.
Wondering if an empty class could impersonate this role.
internal class Unit
{
}
For example in language-ext library, the author used a struct.
Is there any benefit in this choice?
Solution 1:[1]
System.ValueTuple (without generic argument) is very much unit in C#. The source code is open.
Solution 2:[2]
I have used this Unit type as a reference: https://github.com/louthy/language-ext/blob/main/LanguageExt.Core/DataTypes/Unit/Unit.cs
Coming from a functional extension library.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | chwarr |
| Solution 2 | avolkmann |
