[GHC] #14296: Add `Lift Exp` instance to `Language.Haskell.TH.Syntax`
GHC
ghc-devs at haskell.org
Fri Sep 29 14:09:17 UTC 2017
#14296: Add `Lift Exp` instance to `Language.Haskell.TH.Syntax`
-------------------------------------+-------------------------------------
Reporter: heisenbug | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Template Haskell | Version: 8.2.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Poor/confusing | Unknown/Multiple
error message | Test Case:
Blocked By: | Blocking:
Related Tickets: #14030 | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by heisenbug):
Replying to [comment:4 RyanGlScott]:
> <SNIP>
>
> But it's easy to subvert this with your proposed `Lift Exp` instance,
since you can have, e.g.:
>
> {{{#!hs
> uhOh :: Exp
> uhOh = lift "uhOh"
> }}}
>
You mean
{{{#!hs
uhOh :: ExpQ
uhOh = lift "uhOh"
}}}
> Now `$(lift uhOh)` won't be an `Exp`, but rather a `String`. This is not
at all what we want.
Totally agree. My question is when this happens in a `[p|($uhOh ->
binding)|]` and this ends up in a splice, ultimately being compiled by
GHC, then I'll get a type error "Expected `Exp`, got: `String`", correct?
>
> Replying to [comment:3 heisenbug]:
> > What about the derivation mechanism for `Lift` instances? Will it do
''the right thing'' in this case too?
>
> Right. Here is an except of the `-ddump-deriv` output from deriving a
`Lift` instance for `Exp`:
>
> {{{#!hs
> deriving instance Lift Exp
>
> ===>
>
> instance Lift Exp where
> lift (VarE a) = conE 'VarE `appE` lift a
> lift (ConE a) = conE 'ConE `appE` lift a
> lift (AppE f x) = conE 'AppE `appE` lift f `appE` lift x
> ...
> }}}
>
> Now calling `lift` on an `Exp` will produce an `ExpQ` that represents an
`Exp` value. It's quite meta, granted, but that's how it should be :)
That's good. Thanks!
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14296#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list