How am I supposed to use std::optional, whithout functions like map and flatMap/bind
Maybe in Haskell is perfectly usable without
fmap, it represents a value that may or may not be there. It also brings to the type system the distinction so you need to handle both cases.
whats the advantage using a std::optional vs for example returning -1, or a nullptr from a function if it fails to compute a result?
How do you know what the error condition is? Is it
nullptr or something else? If I have both a
unsigned int and
int return value and the
int version previously returned
-1 should you change them both to
MAX_INT or make them return different values?
std::optional avoids the problem.
And more important for me, why wasn't std::optional designed to be a monad, is there a reason?
Does C++ have monads at the moment? Until a different abstraction than the container one there isn't really a way to add that functionality.