Admin message

Due to a large amount of spam we do not allow new users to create repositories, they are "external" users. If you are a new user and want to create a repository, for example for forking GHC, open a new issue on ghc/ghc using the "get-verified" issue template

Allow declaration splices inside declaration brackets
I would like to be able to write code like: ``` {-# LANGUAGE TemplateHaskell #-} import Language.Haskell.TH decs :: Q [Dec] decs = [d| data MyType = MyCon | MyOtherCon val1 :: MyType val1 = MyCon val2 :: MyType val2 = MyOtherCon $( do let mkFun v i = [| if $v == i then val1 else val2 |] [d| fun3 x = $(mkFun [| x |] 3) fun4 x = $(mkFun [| x |] 4) |] ) |] ``` but GHC says: ``` $ ghci decSplices.hs GHCi, version 7.5.20120420: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( decSplices.hs, interpreted ) decSplices.hs:15:15: Declaration splices are not permitted inside declaration brackets Failed, modules loaded: none. ``` As far as I can see there is no technical reason why this couldn't work, with a splice within a declaration bracket splitting the declarations into 3. The declarations before the splice would be renamed, typechecked etc first, then those in the splice, and finally those after the splice. <details><summary>Trac metadata</summary> | Trac field | Value | | ---------------------- | ---------------- | | Version | 7.4.1 | | Type | FeatureRequest | | TypeOfFailure | OtherFailure | | Priority | normal | | Resolution | Unresolved | | Component | Template Haskell | | Test case | | | Differential revisions | | | BlockedBy | | | Related | | | Blocking | | | CC | | | Operating system | | | Architecture | | </details> <!-- {"blocked_by":[],"summary":"Allow declaration splices inside declaration brackets","status":"New","operating_system":"","component":"Template Haskell","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.4.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"FeatureRequest","description":"I would like to be able to write code like:\r\n{{{\r\n{-# LANGUAGE TemplateHaskell #-}\r\n\r\nimport Language.Haskell.TH\r\n\r\ndecs :: Q [Dec]\r\ndecs = [d| data MyType = MyCon | MyOtherCon\r\n\r\n val1 :: MyType\r\n val1 = MyCon\r\n\r\n val2 :: MyType\r\n val2 = MyOtherCon\r\n\r\n $( do let mkFun v i = [| if $v == i then val1 else val2 |]\r\n [d| fun3 x = $(mkFun [| x |] 3)\r\n fun4 x = $(mkFun [| x |] 4) |] ) |]\r\n}}}\r\nbut GHC says:\r\n{{{\r\n$ ghci decSplices.hs\r\nGHCi, version 7.5.20120420: http://www.haskell.org/ghc/ :? for help\r\nLoading package ghc-prim ... linking ... done.\r\nLoading package integer-gmp ... linking ... done.\r\nLoading package base ... linking ... done.\r\n[1 of 1] Compiling Main ( decSplices.hs, interpreted )\r\n\r\ndecSplices.hs:15:15:\r\n Declaration splices are not permitted inside declaration brackets\r\nFailed, modules loaded: none.\r\n}}}\r\n\r\nAs far as I can see there is no technical reason why this couldn't work, with a splice within a declaration bracket splitting the declarations into 3. The declarations before the splice would be renamed, typechecked etc first, then those in the splice, and finally those after the splice.\r\n","type_of_failure":"OtherFailure","blocking":[]} -->
issue