#960: Lexical call site string
--------------------------------+-------------------------------------------
Reporter: [EMAIL PROTECTED] | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 6.6
Severity: normal | Resolution:
Keywords: | Difficulty: Unknown
Testcase: | Architecture: Unknown
Os: Unknown |
--------------------------------+-------------------------------------------
Comment (by simonpj):
A neat way to do this might be to extend Template Haskell slightly, to
provide
{{{
currentLocation :: Q (Filepath, Int)
}}}
giving the filename and location of the current splice. (This is rather
similar to the existing Template Haskell function
[http://www.haskell.org/ghc/docs/latest/html/libraries/template-haskell
/Language-Haskell-TH-Syntax.html#v%3AcurrentModule currentModule].)
Then you could define
{{{
callSite :: ExpQ
callSite = do { (f,n) <- currentLocation
; return (LitE (StringL (f ++ ":" ++ show n))) }
}}}
And use it thus:
{{{
error ("woggle at" ++ $callSite)
}}}
Since the Template Haskell splice `$callSite` is a TH splice, it's ok for
it to grab contextual information.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/960>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs