7 ms·
In .NET specifically a reason I can think about doing that is that you'd need to implement your visitor twice, as the type argument cannot be void (if I recall
by frabert 5y ago
In .NET specifically a reason I can think about doing that is that you'd need to implement your visitor twice, as the type argument cannot be void (if I recall correctly).
- Joker_vD 5y agoIt can't be void, but writing public sealed class Unit { private static Unit m_value = new Unit(); public static Unit Value => m_value; public Unit() { } public override string ToString() => "()"; public override bool Equals(object obj) => obj is Unit; public override int GetHashCode(object obj) => 0; } and then using it ("return Unit.Value") in place of void is really not that big a problem.
- contravariant 5y agoTrue, but I just never quite managed to understand why you'd want your visitor to return nothing. And if you did why it was too much hassle to just return '0' or something.