Skip to content

Somehow detect splicing in ghci

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 [])
>>> 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 makeLenses (discussed here, there, 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

>>> data A = B { _int :: Int }
>>> pure []; makeLenses ''A

>>> view int (B 42)
42
>>> data A = B { _int :: Int }; makeLenses ''A

>>> view int (B 42)
42
Edited by Icelandjack
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information