Comments (8)
Well it turns out that the changes I'm making for v4 effectively force my hand here. I've never been happy with having Option<T>
and Maybe<T>
, so the latter is going and the former is becoming a struct. To make that play nicely with null
:
- Assigning
null
toSome
will throw, - An implicit cast from
null
to an option will result in anone
, Option<RefType>.None == null
.
from succinct.
The following was implemented in v4:
Assigning
null
toSome
will throw,
An implicit cast fromnull
to an option will result in anone
,
Option<RefType>.None == null
.
Closing as implemented.
from succinct.
Thanks for reporting this.
I'll mark this as a bug for now, until I have time to properly look at the code to assess why it's like it is and whether it's by design or not and whether that design is sensible or not.
from succinct.
This was definitely by design. null
is a valid value for a string. However, I accept it's arguably flawed design, so I'd be happy to change it ... except what then happens with C# 8 when we have nullable reference types? I'd expect Maybe<string?>
to definitely accept null
then, and Maybe<string>
to throw, but I don't know how that'll work. I need to ask around to see if there's a view amongst the language team as to how that'll be supported, if at all.
Quick update to this: these LDM notes are relevant to this topic.
from succinct.
I get your point, but does a Maybe<string?>
make sense ? What I mean by that is that as far as I understand the objective of Maybe, Maybe<string?>.Some(null)
does not mean anything (by definition, null is not "some"). So back to what I was mentioning before, I would go for either throwing in case of Maybe<string?>.Some(null)
, or maybe (because you're right, null is a valid value for string?
), making Maybe<string?>.Some(null)
behave the same way as Maybe<string?>.None()
.
What do you think ?
from succinct.
Sounds nice!
from succinct.
@xlecoustillier, since this topic is of interest to you, I'd like your opinion on a related topic, please.
What should I do with unions? Taking an extreme case, if I create a Union<int, None>
(not actually possible as I do not expose None
as a type, but for the sake of argument, let's say I did), it seems reasonable that it should behave the same as Option<int>
with regards to null
. But then what if I created a Union<string, List<string>>
. What is it's relationship to null
now?
My first though was to create yet another breaking change and have unions throw exceptions is given a null
. But since I'm turning them into structs, I could do Union<string, List<string>> u = default;
and avoid that null
detection. I would therefore have to either ignore that problem, as have runtime checking for null
for every action performed on a union after creation. That would be slower than current behaviour.
So I'm tempted to just say that Option
is a special case with regard to null
. Unions do nothing special with them. Do you have an opinion on this choice? Thanks.
from succinct.
Interesting question.
From my point of view, default(Union<T1, T2>)
does not really make sense, as Union
s (and Either
s) should always hold exactly one value.
Of course, there is no way to avoid this behavior, even if we could consider this as an error in itself.
In an ideal world, a call to default(Union<T1, T2>)
should throw or something, but I don't think this is possible.
So I would go for checking against null each time as you mentioned, or maybe have a property IsValid
or something that would initialize to false
in case of default
(and to true
in every other case, obviously) and check that instead.
Do you really think it would affect performance ? If yes, and if it's a problem, I personally can live with a default, as, again, it makes no sense and thus should not be used too much, even by mistake.
from succinct.
Related Issues (20)
- Generic ValueOrError HOT 3
- A non-exception Value<T> alternative for unions HOT 2
- SuccincT Roadmap HOT 12
- When will version 3.1.1 be published to NuGet? HOT 3
- Remove Maybe type and change Option to be a readonly struct HOT 5
- Checklist for the v4 release HOT 1
- As C# 7 now supports discards, the Ignore function is redundant and should be removed HOT 1
- As C# 7 now supports discards, the Ignore function is redundant and should be removed HOT 1
- Add pattern matching to the Either type HOT 1
- Runtime Exception of type System.IO.FileNotFoundException HOT 4
- Change enum parsers to use Enum generic constraint HOT 1
- Add positional pattern matching support to Option<T> HOT 1
- Add positional pattern matching support to ValueOrError types HOT 1
- Add positional pattern matching support to Success<T> HOT 1
- Add positional pattern matching support to Either<TL,TR> HOT 1
- Add positional pattern matching support to Union types HOT 1
- Investigate adding cons support for async streams
- Remove the use of <T> at the end of Succinc<T>
- Create a new release of SuccincT, targeting .NET 6, with all the redundant features removed HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from succinct.