question about ghci printing process

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
TP
Reply | Threaded
Open this post in threaded view
|

question about ghci printing process

TP
Hi all,

Learning Template Haskell, I try to understand what happens when
experimenting in ghci:

$ ghci -XTemplateHaskell
> :m + Language.Haskell.TH
> runQ [| \x -> 1 |]
LamE [VarP x_0] (LitE (IntegerL 1))

Indeed, we have:

> :t runQ [| \x -> 1 |]
runQ [| \x -> 1 |] :: Language.Haskell.TH.Syntax.Quasi m => m Exp

where m is any monad instance of Language.Haskell.TH.Syntax.Quasi.

I believed that to be able to print a value in ghci, its type has to be an
instance of Show. But `Exp` is an instance of Show, not `m Exp`:

> :i Show
[...]
  -- Defined in `Language.Haskell.TH.Syntax'
instance Show Fixity -- Defined in `Language.Haskell.TH.Syntax'
instance Show FamFlavour -- Defined in `Language.Haskell.TH.Syntax'
instance Show Exp -- Defined in `Language.Haskell.TH.Syntax'
instance Show Dec -- Defined in `Language.Haskell.TH.Syntax'
instance Show Con -- Defined in `Language.Haskell.TH.Syntax'
instance Show Clause -- Defined in `Language.Haskell.TH.Syntax'
instance Show Callconv -- Defined in `Language.Haskell.TH.Syntax'
instance Show Body -- Defined in `Language.Haskell.TH.Syntax'
instance Show Float -- Defined in `GHC.Float'
instance Show Double -- Defined in `GHC.Float'

So, how does gchi print `runQ [| \x -> 1 |]`?

Thanks in advance,

TP



Reply | Threaded
Open this post in threaded view
|

question about ghci printing process

Daniel Trstenjak-2

Hi TP,

> So, how does gchi print `runQ [| \x -> 1 |]`?

I think the type in this context is 'IO Exp', there's also the instance 'Quasi IO'
and ghci seems to have some kind of special case for the IO monad containing something showable.

Prelude> return "eee"
"eee"

Prelude> return $ \e -> e + 1
Prelude>


Greetings,
Daniel