There is a subtle difference between Haskell Either and Gleam Result.
data Either a b = Left a | Right b ...
** Nothing is *not* an Error.
because the function *worked*, not because it didn't.
To return Error Nil is to commit the YouTube (social) offence:
"You are an evil-doer who has done something wrong.
I refuse to tell you WHAT you did wrong,
so you can't fix it, you wrong-thinking PEASANT."
Seriously, if you have decided to return Error(x),
x had BETTER be a 'reason' (as Erlang calls it) for WHY it is
an error. The pattern in Erlang is, after all,
{ok,Result} | {error,Reason}.
sans_reason (Left _) = Nothing
sans_reason (Right x) = Just x
with_reason (Nothing) s = Left s
with_reason (Just x) _ = Right x
are trivial conversion functions. As I said, the computer does not care.
There are (at least) three different situations we can consider.
(1) Sometimes there is no answer. Typically a search.
In this case, Maybe is appropriate.
(2) Sometimes you asked a question which fails to have an answer
for a reason.
In this case, Either is appropriate.
(3) Sometimes you asked a sensible question for which the system
might have been expected to produce an answer, but something
went wrong. Numeric overflow, database connection shut down
unexpectedly, hard drive developed a bad block.
In this case, an exception is appropriate.
And of course there are other reasons to use Either. Think of
divide-and-conquer: classify :: Problem -> Either SubProblems EasyProblem.
Because Gleam's Result isn't Haskell's Either in terms of connotations for
human beings, even if they are basically the same to a computer.