Re: [Haskell-cafe] HasCallStack - runtime costs?

Thanks, Eric.
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?
... 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.
class Semiring s where plus :: HasCallStack => s -> s -> s times :: HasCallStack => s -> s -> s I'm curious, why do plus and times take a CallStack?
because I want to (be able to) debug implementations. simplified example: {-# language ConstrainedClassMethods #-} import GHC.Stack.Types class C a where p :: a -> Int q :: HasCallStack => a -> Int instance C () where p x = error "huh" q x = error "huh" Calling q gives more information: *Main> p () *** Exception: huh CallStack (from HasCallStack): error, called at CS.hs:10:9 in main:Main *Main> q () *** Exception: huh CallStack (from HasCallStack): error, called at CS.hs:11:9 in main:Main q, called at <interactive>:44:1 in interactive:Ghci1 it, called at <interactive>:44:1 in interactive:Ghci1 I did not see another way than to change the type of the method in the class. (Which looks terrible of course.) - J.

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
participants (2)
-
Eric Seidel
-
Johannes Waldmann