Re:Null References: The Billion Dollar Mistake – Tony Hoare ...
by SatvikBeri on Monday May 30, 2016 @11:16AM
(#11801679)
I think Option[String] and "String?" are semantically both a union type–they both effectively add one possible value to the underlying type, along with a constructor for naturally extending functions on that type–Kotlin's "?" operator is equivalent to Scala's map or Haskell's fmap, etc.
[ Parent
| on HN ]
Re:Null References: The Billion Dollar Mistake – Tony Hoare ...
by airless_bar on Monday May 30, 2016 @01:06PM
(#11802145)
Option[Option[String]] != String??
Re:Null References: The Billion Dollar Mistake – Tony Hoare ...
by SatvikBeri on Monday May 30, 2016 @03:42PM
(#11802749)
My impression, though I'm not sure, is that Kotlin simply won't allow you to do a double "??". Scala etc. will technically allow Option[Option[Something]], but in practice you would almost never want to use it, and can easily avoid it with flatMap.
Re:Null References: The Billion Dollar Mistake – Tony Hoare ...
by airless_bar on Monday May 30, 2016 @05:36PM
(#11803358)
The whole point of this was to show that Scala's types preserve the structure of the computation.
It might not be very interesting in the Option[Option[String]] case but imagine Try[Either[String, Int]] or List[Future[Double]].
It's a very important distinction.
Collapsing cases is one of the primary thing why exceptions sometimes get a bad rap, and Kotlin (and Ceylon) do the same with ? (and |, &) at the value level.