implicit call stacks should provide a way to get the calling function's name
With implicit call stacks we can get the calling SrcPos and the called function's name, but not the caller function's name. E.g.:
{-# LANGUAGE ImplicitParams, ConstraintKinds #-}
import qualified GHC.Stack as Stack
caller :: IO ()
caller = callee 10
where
callee :: (?stack :: Stack.CallStack) => Int -> IO ()
callee _n = mapM_ print (Stack.getCallStack ?stack)
Gives
("?stack",SrcLoc {srcLocPackage = "main", srcLocModule = "Main", srcLocFile = "T.hs", srcLocStartLine = 9, srcLocStartCol = 36, srcLocEndLine = 9, srcLocEndCol = 42})
("callee",SrcLoc {srcLocPackage = "main", srcLocModule = "Main", srcLocFile = "T.hs", srcLocStartLine = 6, srcLocStartCol = 23, srcLocEndLine = 6, srcLocEndCol = 29})
It would be nice to get the name "caller" as well. It's too bad getCallStack returns pairs instead of an abstract type like Frame. Perhaps a separate Stack.getFrames could do that while getCallStack continues to return pairs for compatibility.
Trac metadata
Trac field | Value |
---|---|
Version | 7.10.3 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |