#5375: Regression in newName
---------------------------------+------------------------------------------
    Reporter:  reinerp           |        Owner:                           
        Type:  bug               |       Status:  new                      
    Priority:  highest           |    Milestone:  7.2.1                    
   Component:  Template Haskell  |      Version:  7.3                      
    Keywords:                    |     Testcase:                           
   Blockedby:                    |   Difficulty:                           
          Os:  Unknown/Multiple  |     Blocking:                           
Architecture:  Unknown/Multiple  |      Failure:  GHC rejects valid program
---------------------------------+------------------------------------------

Comment(by reinerp):

 I should point out another (perhaps more common) need for the "totally
 fresh" semantics. When I write a quasiquoter which antiquotes to Haskell,
 for instance for interpolated strings (see
 [http://hackage.haskell.org/package/interpolatedstring-perl6-0.8.1]),
 consider the following:

 {{{
 f x = [qc|The value of x is {x}|]
 }}}
 (here antiquotation is delimited by {}s.) In this case, I want the
 antiquoted {{{x}}} to refer to {{{f}}}'s parameter. My quasiquotation will
 evaluate to a syntax tree as follows:

 {{{
 f x = $( ... (VarE (mkName "x")) ... )
 }}}

 What happens if I want to bind a variable somewhere in the syntax tree? I
 might for instance want to produce the following:

 {{{
 f x = let theString = "The value of x is "
       in theString ++ show x
 }}}

 In this case the name {{{theString}}} should be totally fresh: it's an
 implementation detail of the quasiquoter, and we don't want its binding to
 capture the variable {{{x}}}. So in this case we want:

 {{{
 f x =
   $(do
       theString <- newName "theString"  -- old semantics are needed here
       return $ LetE [ValD (VarP theString) (NormalB (LitE "The value of x
 is")) []]
                     (InfixE (VarE theString) '(++) (VarE (mkName "x")))
   )
 }}}

 Cheers,
 Reiner

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5375#comment:8>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to