mkName problem
Tomasz Zielonka <[email protected]> Fri, 7 Oct 2005 15:12:24 +0200
| Newsgroups | gmane.comp.lang.haskell.template |
|---|---|
| Message-ID | <[email protected]> |
Hello! The attached code shows a behaviour which I don't understand. This could be a bug in TH or a misunderstanding on my side. The problem is that dynamically bound Names made with mkName sometimes "don't see" the variable. See the code for details. It could be a bit shorter, but I wanted to show why I cat't use the 'var syntax. Try to --make T, then uncomment the marked line in T.hs . Best regards Tomasz _______________________________________________ template-haskell mailing list [email protected] http://www.haskell.org/mailman/listinfo/template-haskell
T.hs
(text/x-haskell, 234 B)
{-# OPTIONS -fglasgow-exts #-}
import Mod
variable = "foo"
variable2 = "bar"
main = do
putStrLn $(expandVars "variable, variable2")
-- It compiles when I uncomment the following line
-- let _ = variable
return ()
Mod.hs
(text/x-haskell, 329 B)
{-# OPTIONS -fglasgow-exts #-}
module Mod where
import Language.Haskell.TH
import List
import Char
expandVars :: String -> Q Exp
expandVars s =
[| concat $(return (ListE (map f (groupBy (\x y -> g x == g y) s)))) |]
where
f x | all g x = VarE (mkName x)
| otherwise = LitE (StringL x)
g = isAlphaNum