[Haskell-cafe] implicit call stacks and calling function

Evan Laforge qdunkan at gmail.com
Mon Mar 7 19:35:31 UTC 2016


I noticed this when I started using the new implicit call stacks
feature.  I didn't bring it up because I figure it probably had a good
reason and was too late to change anyway, but the recent talk about
HasCallStack reminded me and I'm curious.

When you do GHC.Stack.getCallStack you get a [(String, SrcPos)].  The
SrcPos is the position of the calling function, but the String is the
callee function.  So you can't get the name of the calling function.
Instead, you get the name of the function with the call stack
annotation.  That's not so useful because in say a logging function,
I'm interested in the caller's name.  I don't need the name of the
logging function, it's just something boring like "info" or "warn"!

When I switched from a custom preprocessor that sort of implemented
SRCLOC_ANNOTATE, it was definitely nice to lose the custom local
hackery, but not so nice to lose the caller's name.  For tests I used
an unsafe mutable global via unsafePerformIO, otherwise failed tests
can't report the name of the failing test, but the hack doesn't work
for logging.

Is there a reason it was done the way it was, or a way to get the name
of the calling function?


More information about the Haskell-Cafe mailing list