[Haskell-cafe] Callstack Implicit Param for Unsafe Prelude Functions

Eric Seidel eric at seidel.io
Tue Oct 20 17:52:41 UTC 2015


We discussed this back when I implemented the implicit call-stacks, and
decided to be conservative in their use in `base`. There are two reasons
behind the decision:

1. There's a runtime cost to using implicit call-stacks, namely an extra
parameter to each function that uses them (just like regular implicit
parameters).

2. They can clutter otherwise simple type signatures. Compare, e.g., 

    head :: [a] -> a

vs

    head :: (?callStack :: CallStack) => [a] -> a

Adding the implicit call-stack more than doubles the length of the type
signature! This might seem like a silly complaint, but I think there's a
real cognitive overhead there, especially when you consider that Prelude
will be one of the first modules that novices might read the haddocks
for.

GHC HEAD now uses implicit call-stacks for functions that always diverge
(ie error and undefined), but we decided to draw the line there. Of
course, there are plenty of other functions where a call-stack would
make sense, especially partial functions. So I've collected some of the
more common ones in a supplementary package:

    https://hackage.haskell.org/package/located-base

I envision this as a package that you pull in for development, but
perhaps leave out of "production" builds, using some CPP magic. And I'll
happily accept PRs for other functions!

Eric

On Tue, Oct 20, 2015, at 10:29, aditya siram wrote:
> Since the latest base now has a way of getting generating stack traces
> via
> the `CallStack` implicit param, is there any reason not to add that param
> to the error messages of unsafe functions in the Prelude ( and even
> commonly used modules like Data.Maybe/Data.List)?
> 
> The type signature will change but for most users it should be a drop-in
> replacement and a great aid to debugging.
> 
> Thanks!
> -deech
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe


More information about the Haskell-Cafe mailing list