3 ms·
> It pops up everywhere in python libraries. It pops up everywhere because Python has default values and sentinel objects. In a different language with a diff
by masklinn 4y ago
> It pops up everywhere in python libraries.
It pops up everywhere because Python has default values and sentinel objects.
In a different language with a different logic, it wouldn't pop up anywhere as much. And usually (though not always) it doesn't overlap with the need for a null (and / or the distinction doesn't matter).
When it does, you can just add a layer of indirection e.g. `Maybe (Maybe a)`. That's what you get if you store an option in a map, in a language with option types:
lookup :: Ord k => k -> Map k a -> Maybe a
so if you have a
Map k (Maybe a)
(a map from any key to an optional value, aka your standard Java or JS or Python map) lookup will return a `Maybe (Maybe a)`, the outer Maybe is the result of the lookup, and the inner Maybe is the stored value. There is no information loss, and if you don't care about the distinction you can just `join` the result in order to collapse it.