Proposal: System.Environment.getEnv should return Maybe

Simon Marlow marlowsd at gmail.com
Wed Mar 14 14:54:32 CET 2012


On 23/02/2012 21:05, John Meacham wrote:
> On Thu, Feb 23, 2012 at 8:18 AM, Bas van Dijk<v.dijk.bas at gmail.com>  wrote:
>> On 23 February 2012 01:07, Evan Laforge<qdunkan at gmail.com>  wrote:
>>> Good point, I had forgotten about the Prelude catch.  I think I can go
>>> remove a bunch of ScopedTypedVariables now.
>>
>> Note that Prelude.catch has been deprecated in favor of
>> Control.Exception.catch. If you want to catch IOErrors you can either
>> use ScopedTypedVariables or System.IO.Error.catchIOError.
>
> Control.Exception.catch is not in haskell 98 or haskell 2010. It also requires
> pulling in some heavy extensions and actually has fundamentally different
> behavior than Prelude.catch. We definitely should not consider it a
> replacement.

We should consider Control.Exception.catch a generalisation of 
Prelude.catch.  Having both exist was confusing, which is why 
Prelude.catch was deprecated.  It does have a direct replacement: 
System.IO.Error.catchIOError.

catch by itself doesn't require heavy extensions, but it is a bit easier 
to use with pattern types signatures (which is only available with 
ScopedTypeVariables, but that's because we're too lazy to separate them.)

The right getEnv is easily available as (tryIOError . getEnv).  I don't 
disagree with this proposal though - I think we added getEnv at a time 
when we were feeling all gung-ho about exceptions, in retrospect this 
was a bad place to use them.

Cheers,
	Simon



More information about the Libraries mailing list