Proposal: System.Environment.getEnv should return Maybe
Henning Thielemann
lemming at henning-thielemann.de
Sun Mar 11 21:33:17 CET 2012
On Sun, 11 Mar 2012, Brandon Allbery wrote:
> Is looking up a missing key in a Map an exception?
It is certainly an exceptional situation. You want to know the value that
is associated with a key, but the answer is not the wanted value, but no
value at all.
> That is exactly this case ("variable" is really only an appropriate
> term from the standpoint of the shell, which [sometimes inappropriately]
> conflates the environment with its own variables). Or are you arguing
> that that also should be an exception?
"exception" in what sense? Certainly not an exception in IO, since I do
not like the implicitness of exceptions in IO. No I think, Maybe is a
perfect return type for 'lookup'. What I want to say is, that Nothing is
also an exceptional value.
A different question is, how to cope with that value. Abort a sequence of
computations? This can be easily done in the Maybe monad and looks more
like conventional exception handling. Do an alternative computation? This
could be done using 'case' or 'maybe'.
The good thing about Haskell is, that if exceptions would be consistently
handled by types like Maybe, MaybeT, ExceptionalT etc. then we could
really simply choose between different ways of coping with exceptional
values.
More information about the Libraries
mailing list