-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Erasable nullables #24
Comments
We have discussed this on the server, but just to have it documented here too. If we can solve the compatibility issues, I'd be all for an explicit option type. |
C# Nullables are metadata, attributes that doesn't offer any guarentee. On top of what @WhiteBlackGoose propose I propose two interop behavior:
|
I feel strongly that you should be allowed to have nested nullables (i.e. |
This would necessitate that Null isn't a compile time only thing. |
The key here is to keep C# interop both backward and forward (that is, use C# API from Fresh and use Fresh API from C#) but make sure to keep the code safe and consistent.
C#'s approach
C# has a separate type for value type nullables, but has annotations for reference types. It creates some inconsistent behaviour, to be precise:
Inconsistent deconstructure
Inconsistent generics
Consider two methods:
Let's substitute
T = int
:See sharplab.
Erasable nullables
Universal type
Instead of having annotations and a type for value types, I suggest having a single type. To avoid confusion, let's call it Null for now:
C# API from Fresh
C#:
Fresh:
Fresh API from C#
It's exactly the same in the opposite direction. That's how it will be alised runtime-wise: present NRTs as Null<>, present Nullable<> as Null<>.
Null exists only at compile time
Runtime-wise looks like
Unresolved
As type argument
What about cases when there's no way to erase it? E. g. when used as a type argument:
Or,
Should we unconditionally materialize Null<> when used as a type argument?
Then
typeof(Null<>)
will work as expected.Nested nullables
E. g.
Should all but the innermost materialize into
Null
? Should we prohibit this behaviour?Relations with Options
Should we have explicit Option type if we manage to design a consistent nullable?
The text was updated successfully, but these errors were encountered: