News for hackers. Stuff that matters.
Re:Why nullable types? by dragonwriter on Tuesday December 08, 2020 @03:01PM (#25350572)
> I'm not sure what you mean by "compose".

The simplest illustration is the ability to have multiple levels of semantically meaningful optionality:

Option<Option<int>> is a meaningful type, and None, Some(None), and Some(Some(1)) are all meaningfully-distinct values. int? doesn't compose to int?? and has no good way to differentiate what Option<Option<int>> represents as None and Some(None).

Re:Why nullable types? by contravariant on Tuesday December 08, 2020 @03:43PM (#25351078)
Ironically the main advantage of Monads is that Option<Option<int>> has a natural transformation to Option<int>.
Re:Why nullable types? by marcosdumay on Tuesday December 08, 2020 @08:00PM (#25353939)
The reason Option<Option<int>> isn't a problem is because it's a monad, so people will naturally transform it into Option<int> while writing their programs.

There is no irony there. If it wasn't a monad, the GGP would be incorrect, and ad-hock solutions would be very valuable.

Re:Why nullable types? by jerf on Tuesday December 08, 2020 @10:57PM (#25355163)
In a language with Haskell's guarantees, you can mechanically get from the standard "bind" function to prove that "m (m a)" can be converted to "m a" [1]. That function is called "join", and is a lesser-well known way to write monad implementations which is equivalent to the more famous bind function.

(IMHO, join is a better way to understand the typeclass intuitively. The standard bind is better to program with in general use, but much harder to grok.)

So, in Haskell, it's more than just "the APIs would tend to encourage not nesting the types"... having a valid monad implementation means they really are equivalent.

[1]: https://stackoverflow.com/questions/3382210/monad-join-funct...

Re:Why nullable types? by dllthomas on Wednesday December 09, 2020 @12:46AM (#25355734)
They are not equivalent. Join can throw away information - and certainly does for (Maybe (Maybe a) -> Maybe a) and ([[a]] -> [a]).

They would be equivalent if there was an isomorphism, but of course there isn't.