[Haskell-cafe] Use of errorWithoutStackTrace in the Prelude
eric at seidel.io
Wed Dec 7 05:04:02 UTC 2016
The performance impact is part of the rationale, but a bigger issue is
the burden on the type signatures.
Using the new `error` would not be enough to get useful locations for
`head` and friends. The stack trace would only contain the call to error
*inside* head, and not the call to head itself, which is pure noise. If
we wanted to add the call to head, we would have to add a `HasCallStack`
constraint to `head` itself (and all other partial functions).
We discussed this back when I first implemented the implicit
call-stacks, and decided to be conservative with their use in base for
these reasons. Though it is worth noting that at this point we were
still using an explicit implicit parameter instead of the `HasCallStack`
alias, which made the constraint more unfamiliar especially to
newcomers. Perhaps with the new alias the API-cluttering concerns are
less of a problem.
In the meantime, I have a package
that provides callstack-aware variants of many partial functions that I
use, and would happily accept a PR for any others that you use!
On Tue, Dec 6, 2016, at 16:30, Alexis King wrote:
> I noticed that the partial functions in the Prelude use
> errorWithoutStackTrace instead of `error` to provide their error
> messages, which produces significantly worse error messages. I
> stumbled into this when a coworker of mine had trouble tracking
> down a use of `head` that was throwing an exception, but didn’t
> include any information about where it was in the source.
> What exactly is the rationale for this? Is it to avoid the performance
> penalty of passing around the implicit parameter? That seems
> relatively unlikely, since the performance hit seems trivial, but
> perhaps it’s to avoid breaking tests that depend on error messages?
> I think it would be nice for Prelude-provided functions to be
> informative by default, so the change seems worth it to me, but I’m
> wondering if there’s something I’ve overlooked.
> Also, if the answer really is “no, errorWithoutStackTrace is correct”,
> is the expectation that people will use -prof if they want stacks?
> This seems a bit frustrating to a newcomer who might not understand
> anything more complicated than running `stack test` and might not
> be able to figure out how to pass the right options (especially
> since options need to be passed both at compile-time and at runtime).
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> Only members subscribed via the mailman list are allowed to post.
More information about the Haskell-Cafe