[Haskell-beginners] question about ghci printing process

TP paratribulations at free.fr
Fri Jun 28 13:08:24 CEST 2013


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




More information about the Beginners mailing list