[Nix-dev] Re: Proposal: tryCatch function

Nicolas Pierron nicolas.b.pierron at gmail.com
Tue Jan 6 17:55:23 CET 2009


On Tue, Jan 6, 2009 at 11:59, Andres Loeh <andres.loeh at googlemail.com> wrote:
>> We have enabled side effects already. Without caring about evaluation
>> order. I mean "trace" builtin. It has 2 main properties, though: it
>> never changes what derivations are constructed and it only gives
>> end-user a bit more information that can be filtered out if not helpful.
>>
>> tryCatch lacks the first property, and because of that I consider it
>> harmful. tryRethrow is just like trace, and I am not sure that IO purity
>> is worth preserving (if it doesn't affect actual build purity).
>
> Regarding tryCatch: as far as I understood it, it doesn't introduce any
> impurity, so I don't find it particularly problematic to add.

The impurty problem is due to the problem that anything can come out
the catch function.

tryCatch ((throw "foo") + (throw "bar")) (msg: msg) == "foo" OR "bar" ???

In the case the throw statement does not brake the evaluation (and
possibly change the return value).

tryRethrow does not have this issue because it is just a function
which handles the error computation, but at the end an error will be
raised.

> But I doubt
> its usefulness given the lazy nature of the language and the escaping
> issues.

I don't see why the escaping with the laziness can broke this clean
"stack trace".

> Plus, I think it sends the wrong message, because it
> encourages the use of
> exceptions (throw), which are impure already, and I don't like that very
> much.

As you said, this is only used for error computation, then this is a
kind of premature exit.  So, yes "throw" is impure but this is just a
short way to say that something goes wrong.

> I think we should strive for ways to be able to program with as few
> as possible uses of throw.

True, but we still need some because the stack trace just give you the
function name, the lines but not the argument used to compute your
function or something more talkative.

-- 
Nicolas Pierron
http://www.linkedin.com/in/nicolasbpierron
- If you are doing something twice then you should try to do it once.



More information about the nix-dev mailing list