Proposal: System.Environment.getEnv should return Maybe

Brandon Allbery allbery.b at gmail.com
Mon Mar 12 02:18:37 CET 2012


On Sun, Mar 11, 2012 at 16:33, Henning Thielemann <
lemming at henning-thielemann.de> wrote:

> 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.


So you will insist that lookup when the key doesn't exist throw an
exception? If not, why not?

If we're going to make interfacing with the system as difficult and
minetrap-strewn as possible, then let's cut to the chase and switch to
Agda.  Or we need to change a bunch of IO (Maybe x) to throw approved
exceptions and make them suitably difficult to use for our walled garden
instead of thinking about whether that's appropriate.

Or, just maybe, we just need to stop thinking of
it's-in-IO-it-should-throw-an-exception-at-every-opportunity-instead-of-being-*usable*.
 IO's enough of a sewer as it is without turning it into
don't-think-about-it-just-hork-a-hairball too.


> "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.
>

(So, you just tossed in <stdrant.h> C-style without looking at the context?)

The context is that getEnv currently throws an IO exception if the name
isn't found, and we'd like it to be IO (Maybe String) because it's really a
keyed store where absence of the key isn't really justification for an IO
exception, but is a reasonable use for a Maybe.  It's the cranky IO
exception that needs to go away, not the notion of an exceptional condition
in general.

-- 
brandon s allbery                                      allbery.b at gmail.com
wandering unix systems administrator (available)     (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20120311/620ea1e0/attachment.htm>


More information about the Libraries mailing list