Hacker News new | past | comments | ask | show | jobs | submit login

this is called a bottom type in a type system. In JVM languages null and the throw expression return the bottom type.

The only other option is to not have nil values.




Or to encapsulate a nil in a Maybe monad, so that you only have to deal with it in contexts where you explicity denote acceptance of nils. Then the type system won't let you get away with ignoring the possibility of a nil.


you can do a maybe monad without nil types by substituting nil with a single-valued singleton type


> The only other option is to not have nil values.

Rust has a bottom type (!)[0] without it implementing all traits by default while using a different type (Result) for error propagation. Plus having nil/null as a a value of the bottom type violates some aspects of bottomness.

[0] https://github.com/rust-lang/rfcs/blob/master/text/1216-bang...


The problem is "null" being a value in all (non primitive) types, not only the bottom type. You specify "String", but you can have "null" too. When everything is optional, how do you specify that function foo really takes a String, not null? (https://stackoverflow.com/questions/4963300/which-notnull-ja...)


> The problem is "null" being a value in all (non primitive) types, not only the bottom type.

Null is not a value of bottom type. Bottom type has no values.


Thanks, you are right, the bottom type has no value. I meant the "Null" type, which contains a single value, "null".




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: