[GHC] #12410: Somehow detect splicing in ghci

GHC ghc-devs at haskell.org
Tue Jul 19 16:59:26 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
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 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]):

 {{{
 >>> 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>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list