[Haskell-cafe] HasCallStack - runtime costs?
Johannes Waldmann
johannes.waldmann at htwk-leipzig.de
Fri Mar 4 17:18:18 UTC 2016
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.
More information about the Haskell-Cafe
mailing list