[GHC] #12410: Somehow detect splicing in ghci
GHC
ghc-devs at haskell.org
Tue Jul 19 17:10:47 UTC 2016
#12410: Somehow detect splicing in ghci
-------------------------------------+-------------------------------------
Reporter: Iceland_jack | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | 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: |
-------------------------------------+-------------------------------------
Description changed by Iceland_jack:
@@ -25,1 +25,3 @@
- over-tea-6 here], [https://github.com/ekmett/lens/issues/461 there]):
+ over-tea-6 here], [https://github.com/ekmett/lens/issues/461 there],
+ [https://www.reddit.com/r/haskelltil/comments/3ghacj/you_can_use_template_haskell_functions_like/
+ hither]):
New description:
I'm no TH expert but currently it seems you need a hack (adding `data X ;`
or `pure []`) to do the following
{{{
ghci> $(reify ''() >>= runIO.print >> return [])
<interactive>:210:3: error:
• Couldn't match type ‘[t0]’ with ‘Exp’
Expected type: ExpQ
Actual type: Q [t0]
• In the expression: reify ''() >>= runIO . print >> return []
In the untyped splice: $(reify ''() >>= runIO . print >> return [])
}}}
{{{#!hs
>>> data X; $(reify ''() >>= runIO.print >> return [])
TyConI (DataD [] GHC.Tuple.() [] Nothing [NormalC GHC.Tuple.() []] [])
>>> pure []; $(reify ''() >>= runIO.print >> return [])
TyConI (DataD [] GHC.Tuple.() [] Nothing [NormalC GHC.Tuple.() []] [])
}}}
Same with [https://hackage.haskell.org/package/lens-4.14/docs/Control-
Lens-TH.html#v:makeLenses makeLenses] (discussed [https://artyom.me/lens-
over-tea-6 here], [https://github.com/ekmett/lens/issues/461 there],
[https://www.reddit.com/r/haskelltil/comments/3ghacj/you_can_use_template_haskell_functions_like/
hither]):
{{{
>>> data A = B { _int :: Int }
>>> makeLenses ''A
<interactive>:209:1: error:
• No instance for (Show DecsQ) arising from a use of ‘print’
• In a stmt of an interactive GHCi command: print it
}}}
the following two work
{{{#!hs
>>> data A = B { _int :: Int }
>>> pure []; makeLenses ''A
>>> view int (B 42)
42
}}}
{{{#!hs
>>> data A = B { _int :: Int }; makeLenses ''A
>>> view int (B 42)
42
}}}
--
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12410#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list