diff options
Diffstat (limited to 'docs')
-rw-r--r-- | docs/users_guide/7.12.1-notes.rst | 2 | ||||
-rw-r--r-- | docs/users_guide/glasgow_exts.rst | 28 |
2 files changed, 24 insertions, 6 deletions
diff --git a/docs/users_guide/7.12.1-notes.rst b/docs/users_guide/7.12.1-notes.rst index 678a9778a8..bb4c55e71e 100644 --- a/docs/users_guide/7.12.1-notes.rst +++ b/docs/users_guide/7.12.1-notes.rst @@ -393,7 +393,7 @@ See ``changelog.md`` in the ``base`` package for full release notes. - ``GHC.Stack`` exports two new types ``SrcLoc`` and ``CallStack``. A ``SrcLoc`` contains package, module, and file names, as well as start - and end positions. A ``CallStack`` is a ``[(String, SrcLoc)]``, + and end positions. A ``CallStack`` is essentially a ``[(String, SrcLoc)]``, sorted by most-recent call. - ``error`` and ``undefined`` will now report a partial stack-trace diff --git a/docs/users_guide/glasgow_exts.rst b/docs/users_guide/glasgow_exts.rst index f28295a86f..d847517140 100644 --- a/docs/users_guide/glasgow_exts.rst +++ b/docs/users_guide/glasgow_exts.rst @@ -8282,14 +8282,14 @@ a type signature for ``y``, then ``y`` will get type ``let`` will see the inner binding of ``?x``, so ``(f 9)`` will return ``14``. -.. _implicit-parameters-special: +.. _implicit-callstacks: -Special implicit parameters -~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Implicit CallStacks +~~~~~~~~~~~~~~~~~~~ Implicit parameters of the new ``base`` type ``GHC.Stack.CallStack`` are -treated specially in function calls, the solver automatically appends -the source location of the call to the ``CallStack`` in the +treated specially in function calls, the solver automatically pushes +the source location of the call onto the ``CallStack`` in the environment. For example :: @@ -8342,6 +8342,24 @@ package, module, and file name, as well as the line and column numbers. GHC will infer ``CallStack`` constraints using the same rules as for ordinary implicit parameters. +``GHC.Stack`` additionally exports a function ``freezeCallStack`` that +allows users to freeze a ``CallStack``, preventing any future push +operations from having an effect. This can be used by library authors +to prevent ``CallStack``s from exposing unecessary implementation +details. Consider the ``head`` example above, the ``myerror`` line in +the printed stack is not particularly enlightening, so we might choose +to surpress it by freezing the ``CallStack`` that we pass to ``myerror``. + +:: + head :: (?callStack :: CallStack) => [a] -> a + head [] = let ?callStack = freezeCallStack ?callStack in myerror "empty" + head (x:xs) = x + + ghci> head []] + *** Exception: empty + CallStack (from ImplicitParams): + head, called at Bad.hs:12:7 in main:Bad + .. _kinding: |