[Haskell-cafe] implicit call stacks and calling function

Eric Seidel eric at seidel.io
Mon Mar 7 19:46:55 UTC 2016

On Mon, Mar 7, 2016, at 11:35, Evan Laforge wrote:
> 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"!
> Is there a reason it was done the way it was, or a way to get the name
> of the calling function?

The reason we provide the name of the callee is that the standard format
for a stack trace is callee+pos :)

You point about wanting the caller's name too is well-taken though. In
most languages you can just look at the next item in the stack to grab
the caller, but with HasCallStack there may be no next item... I doubt
it would be hard to add the caller's name too, I'd be happy to look into
it post-ICFP. Would you mind filing a ticket?


More information about the Haskell-Cafe mailing list