3 ms·
Why can't a compiler essentially do the same for null as you're describing for None?
by Graffur 6y ago
Why can't a compiler essentially do the same for null as you're describing for None?
- samatman 6y agoIt's basically a definitional thing. An Option type means you must specify Some (pointer) or could-be-None (null, NULL pointer) and the compiler will enforce the distinction. Generally this comes with exhaustive pattern matching, so you can turn Some<T> into <T>, and handle None by raising an error or assigning a default or blowing demons out your nose. None and null are the same thing, the name isn't the important part. Zig, for example, has optional types as ?*Foo, and calls the null pointer "null".