[Haskell-cafe] HasCallStack - runtime costs?

Eric Seidel eric at seidel.io
Sat Mar 5 16:33:18 UTC 2016


On Fri, Mar 4, 2016, at 09:18, Johannes Waldmann wrote:
> > If you import a function with a HasCallStack constraint
> > there's no way to disable the overhead
> 
> But then this means that each library
> should avoid these constraints?
> 
> Or not, because this rightly scares away users
> from calling nontotal functions?

I think it's a matter of judgment. For non-recursive functions like head
and tail, the overhead is probably not large enough to be noticeable.
With recursive functions, on the other hand, the overhead compounds
itself as you'll get a new callstack entry for each recursive call. So
if you really want your recursive function to take a CallStack, you
might refactor it so the recursion is handled by a helper function that
doesn't take a CallStack.

> > ... with a couple special rules for
> > building dictionaries in GHC's constraint solver.
> 
> then activation of these special rules could be a compiler switch?
> Though it'd probably create a mess with separate compilation/linking.
> But switching via CPP will do the same.

Yes this would have (roughly) the same effect as my CPP suggestion, the
problem being that you'd have to recompile every module that used
HasCallStack.
 
Eric


More information about the Haskell-Cafe mailing list