News for hackers. Stuff that matters.
Re:Kotlin: The Problem with null by user2994cb on Friday January 12, 2018 @04:50PM (#16136643)
Aren't null pointers just a variation on the Maybe Monad?
Re:Kotlin: The Problem with null by anaphylactic on Friday January 12, 2018 @05:20PM (#16136856)
Maybe is just another Optional type, but with a much weirder name, so that's pretty obvious. But this makes me wonder - does Haskell optimize `Maybe`-like types down to a null-pointer, like Rust does?
Re:Kotlin: The Problem with null by user2994cb on Friday January 12, 2018 @06:22PM (#16137174)
Dunno, but I'd have thought that you can make None look like a null pointer, but Some(p) needs to be tagged in some way.
Re:Kotlin: The Problem with null by user2994cb on Saturday January 13, 2018 @12:13AM (#16138358)
Actually, having Some(x) be just a pointer to x seems to work fine without an explicit tag, as dragonwriter says below.
Re:Kotlin: The Problem with null by masklinn on Saturday January 13, 2018 @06:40AM (#16139205)
null pointers can be encoded as an option type[0] (that's basically what languages like Swift or Rust do, they eschew nullable pointers and wrap non-nullable pointers in an option type instead), but they are not because

1. you don't have the attending type-safety of knowing that some pointers can't be null

2. the compiler requiring checking for nullity before every pointer access would be horrendously unwieldy

[0] which can then be compiled back to a regular nullable pointer at runtime

Re:Kotlin: The Problem with null by Zpalmtree on Friday January 12, 2018 @11:53PM (#16138328)
You're forced to check for a Nothing value, wheras with a null pointer you can happily use it like a normal value.
Re:Kotlin: The Problem with null by simon_o on Friday January 12, 2018 @07:43PM (#16137562)
No, because Option/Maybe can nested, nulls can't.
Re:Kotlin: The Problem with null by dragonwriter on Friday January 12, 2018 @07:55PM (#16137602)
Nulls can be nested if you are using a language with explicit pointer types.

E.g.,

  Int*** x;
Can be a lot like

  Maybe Maybe Maybe Int
It's just that in languages where a type like Integer really means “an integer or a null", the nullability doesn't nest, and no one wants to deal with naked pointers.