There's no need to construct a static type to hold both possibilities because variables can already hold all types.
There's no need to construct a static type to hold both possibilities because variables can already hold all types.
0: https://www.greenbird.com/news/railway-oriented-programming-....
https://fsharpforfunandprofit.com/rop/
And his 'Against Railway-Oriented Programming':
https://fsharpforfunandprofit.com/posts/against-railway-orie...
Imagine a code without `if result is not None` basically!
if a is None:
raise Exception()
if a.b is None:
raise Exception()
if a.b.c is None:
raise Exception()
One of the advantages of Python/Typescript style type hinting is that it avoids the mega-nested `if`s that you often have to resort to in Rust. In Rust the above would not work: if a.is_none() {
bail!();
}
if a.b. // nope! a is still Option<>.
It may be possible to fix that when enum variants are distinct types but as it stands you often have to do lots of indenting. foo | None
is not a tolerable replacement for Maybe(foo)
When None is a valid value of type foo.Which is obviously true when foo is NoneType, but more to the point is true when foo is (bar | None).
Maybe composes, “... | None” does not.
Even if true, so what? The utility of Maybe/Result datastructures isn't limited to their use in typechecking, though with a proper static typechecker, that is part of their use.
Wanting something that's ergonomic for free composition where you aren't anticipating all the potential uses where it is defined is where real monadic Maybe/Result types shine, and once you pull them in to a code base it sometimes makes sense to use them for the local cases, too.