Haskell template name quoting desugar 'x to NameG?

Can I always expect the single quote syntax for desugar for the constructor NameG? for example does

'x

always desugar for

(Name (OccName "x") (NameG VarName (PkgName "some-package") (ModName "SomeModule")))

This information should always be there, after the name resolution, which is the stage. The Haskell template starts after, right? And I could not quote the local names, although I am only interested in quoting top-level names.

Context: I want to write a function that returns a uniquely qualified identifier. This is a partial function because I cannot limit the input, since Template Haskell does not have any GADT or anything else, while I do not want to wrap the output with uncertainty. And I don’t want to use a quasicycler or splicing if I 'will. I want to prove that this partial function is safe at runtime when used as described above , quoting top-level names in the same module , given:

name (Name occ (NameG _ pkg mod)) = Unique occ pkg mod

I want to have a function like:

(<=>) :: Name -> a -> Named a

Given:

data Named a = Named a Unique

to annotate variable bindings:

x = 'x
 <=> ...

without the need for strong splice syntax $(name ...)and cause splice at compile time:

x = $(name 'x)
 <=> ...

.

https://downloads.haskell.org/~ghc/7.8.3/docs/html/users_guide/template-haskell.html https://hackage.haskell.org/package/template-haskell-2.8.0.0/docs/src/Language-Haskell-TH-Syntax.html#Name didn ' t .

(p.s. , (, ''T) , , ).

+4
1

" , , Q:

name :: Name -> ExpQ
name (Name occ (NameG _ pkg mod)) = [| Unique occ pkg mod |]
name n = fail $ "invalid name: "++ gshow n

$(name 'show) :: Unique name 'show :: Unique. Name (, - mkName), .

+1

Source: https://habr.com/ru/post/1570750/


All Articles