Proposal: System.Environment.getEnv should return Maybe

John Meacham john at
Thu Feb 23 00:51:51 CET 2012

On Wed, Feb 22, 2012 at 3:05 PM, Evan Laforge <qdunkan at> wrote:
> It's awkward and surprising how getEnv throws an exception when an env
> var is not set, since it's very common for env vars to be optional,
> and it's not convenient to catch exceptions in haskell (I have to look
> up Control.Exception every time, and then add LANGUAGE

For true IO exceptions, you should be using the Prelude.catch mechanism.
It's the right thing to do and makes your program more portable as a bonus.
It is quite unfortunate that IO exceptions became conflated with imprecise
and dynamic exceptions and clash in their names. They really are different
beasts alltogether.

In particular, IO can be fully understood via the following desugaring.

data IO a = IO (State -> (State,Either IOException a))

imprecise exceptions break this cognitive desugaring and cause odd things
like throwIO and raise having slightly different and confusing syntax and
APIs being unclear on what they mean by 'exception'.

In any case, they will definitely be completely different beasts in jhc if I
decide to implement imprecise exceptions.


More information about the Libraries mailing list