#2221: Can't use quotationes ([| ... |]) insides declaration splices
-----------------------+----------------------------------------------------
    Reporter:  m4dc4p  |       Owner:                  
        Type:  bug     |      Status:  new             
    Priority:  normal  |   Component:  Template Haskell
     Version:  6.8.2   |    Severity:  normal          
    Keywords:          |    Testcase:                  
Architecture:  x86     |          Os:  Windows         
-----------------------+----------------------------------------------------
 Normal Template Haskell allows many levels of splicing and quotations:

 {{{
 > runQ [| (const $([|"Int"|])) |]
 AppE (VarE GHC.Base.const) (LitE (StringL "Int"))
 }}}

 And TH can parse declarations easily:
 {{{
 > runQ [d| type T = Int|]
 [TySynD T [] (ConT GHC.Base.Int)]
 }}}

 But splicing inside a declaration gives a syntax error:

 {{{
 > runQ [d| type T = $([t|Int|])|]
 parse error on input `$('
 }}}

 Another example. Bulat Ziganshin defines the cnst function
 (http://www.haskell.org/bz/th3.htm) as:

 {{{
 cnst 0 str = [| str |]
 cnst n str = [| \_ -> $(cnst (n-1) str) |]
 }}}

 Which evaluates to a function that takes n arguments and returns the
 string given. It would make sense that a function to define a data
 constructor which takes n arguments could be written similarly:

 {{{
 dataCnst n = [d|data D = D $(dataCnst' n)|]
 dataCnst' n = [t|Int|] ++ dataCnst' (n - 1)
 }}}

 Finally, a function that makes a data type which varies the field type
 based on an argument:

 {{{
 dataVar n = [d|data D = D $(dataVar' n)|]
 dataVar' "Int" = ''Int
 dataVar' "String" = ''String
 etc.
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2221>
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