[GHC] #13054: Generating unique names with template haskell

GHC ghc-devs at haskell.org
Wed Jul 26 13:31:49 UTC 2017


#13054: Generating unique names with template haskell
-------------------------------------+-------------------------------------
        Reporter:  tim-m89           |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Template Haskell  |              Version:  8.0.1
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 I also agree that `newName`s should not be exportable! Moreover, I don't
 think you really should be exporting `newGlobalName`s either—but that
 doesn't mean it's a non-use-case! Quite often in Template Haskell code
 you'll want to define top-level functions that are used across other
 functions. For example, in my [http://hackage.haskell.org/package
 /deriving-compat-0.3.6/docs/Data-Enum-Deriving.html deriving-compat]
 library, I've found myself wanting to define a function:

 {{{#!hs
 con2tagFoo :: Foo -> Int#
 }}}

 Like what happens when you derive `Enum` in GHC today, only in Template
 Haskell. This needs to be a top-level identifier, however, since `con2tag`
 functions also get used across multiple `Enum` methods, so I need to
 ensure that this `con2TagFoo` name is globally unique. However, it
 certainly doesn't need to be exported. Currently, the only way to do this
 is with something like `newUniqueName` from comment:2, which isn't robust
 against things like infix names.

 I imagine tim-m89's use case would also be served by `newGlobalName`.

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


More information about the ghc-tickets mailing list