4 ms·
The key with Maybe/Option types is pattern matching ensures you don't forget to handle the case where it is none (it can be meaningful!). If you have a value of
by jroesch 12y ago
The key with Maybe/Option types is pattern matching ensures you don't forget to handle the case where it is none (it can be meaningful!). If you have a value of `Maybe a` you are required to pattern match on it.
case myMaybe of
Nothing -> foundNothing
Just v -> ...
In Python and Ruby any value can be None or nil at anytime.
In stark contrast languages like Rust and Haskell (that have no concept of None/nil/null) this is very useful as you know you always have a value in your variable and not a null.
This means when you do introduce an Option/Maybe type you are saying the null case should be treated with special semantics, exactly what you usually want in a dynamic language.