Option[T]'s are composable. For example, let's say we have a "get" method to get the value for a given key, whose type looks like:
get :: String -> (T | Nil)
get :: String -> Option[T]
let m: Map[String,(Int | Nil)] = make_some_map() let result: (Int | Nil) = m.get("some-key")
With Option[T]:
let m: Map[String,Option[Int]] = make_some_map() let result: Option[Option[Int]] = m.get("some-key")
So there is an observable and potentially useful difference between (T | Nil) and Option[T].
Option[T]'s are composable. For example, let's say we have a "get" method to get the value for a given key, whose type looks like:
If we were using Option[T]'s, it would look like: So let's say we have a map, and want to lookup a key (syntax is made-up): If result is nil, was the value of the key nil, or was the key not in the map?With Option[T]:
Here result will either be None, in which case the key wasn't in the map, or Some(None), which means the value of the key was None.So there is an observable and potentially useful difference between (T | Nil) and Option[T].