Closed aggieben closed 5 years ago
After thinking about this a bit more, I think this would actually be a net loss in terms of tradeoffs. A happy coincidence is that an uninitialized Maybe<T>
is the same as Maybe<T>.Nothing
. The problem is that there's no way to prevent a user from getting an uninitialized Result<T,E>
, which is incoherent. I'd rather it be possible to have a typed Maybe<T>
or Result<T,E>
variable be set to null than to get an initialized, nonsensical Result<T,E>
. Furthermore, non-nullable reference types are coming in C# 8.0, which will allow us to keep the current behavior and prevent null
references, which is the best of both. I'm content to just wait.
Currently
Maybe
andResult
are implemented as reference types - that is, regular classes. However, I'd like to see these be value types; they would be better off as value types (struct
in C♯) because it would be a compiler-enforced guarantee that they would never benull
. Secondarily it's plausible that there could be a small performance win by doing that, but that's not the motivation here.