<div dir="ltr">Quite a while back, Simon Hengel and I put together a proposal[1] for a new feature in GHC. The basic idea is pretty simple: provide a new pragma that could be used like so:<br><br>error :: String -&gt; a<br>

errorLoc :: IO Location -&gt; String -&gt; a<br>{-# REWRITE_WITH_LOCATION error errorLoc #-}<br><br>Then all usages of `error` would be converted into calls to `errorLoc` by the compiler, passing in the location information of where the call originated from. Our three intended use cases are:<br>

<br>* Locations for failing test cases in a test framework<br>* Locations for log messages<br>* assert/error/undefined<br><br>Note that the current behavior of the assert function[2] already includes this kind of approach, but it is a special case hard-coded into the compiler. This proposal essentially generalizes that behavior and makes it available for all functions, whether included with GHC or user-defined.<br>

<br>The proposal spells out some details of this approach, and contrasts with other methods being used today for the same purpose, such as TH and CPP.<div><br>Michael<br><br>[1] <a href="https://github.com/sol/rewrite-with-location">https://github.com/sol/rewrite-with-location</a><br>

[2] <a href="http://hackage.haskell.org/packages/archive/base/4.6.0.1/doc/html/Control-Exception.html#v:assert">http://hackage.haskell.org/packages/archive/base/4.6.0.1/doc/html/Control-Exception.html#v:assert</a><br></div>

</div>