[GHC] #960: Lexical call site string
GHC
trac at galois.com
Mon Oct 30 15:20:18 EST 2006
#960: Lexical call site string
--------------------------------+-------------------------------------------
Reporter: paul at cogito.org.uk | 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
More information about the Glasgow-haskell-bugs
mailing list