You get the same behaviour if you use return
instead of pure
. To find out what to do, ghci must choose a type for the given expression. ghci's defaulting rules are such that absent other constraints, it chooses IO
for an Applicative
or Monad
instance. Thus it interprets pure 1
as an expression of type IO Integer
. Expressions of type IO a
entered at the prompt are executed and their results are printed, if 1. a
has a Show
instance and 2. a
is not ()
. Thus entering pure 1
at the prompt results in
v <- return (1 :: Integer)
print v
return v
being executed (and the magic variable it
bound to the returned v
). For pure ()
, the special case applies since ()
is considered uninteresting, thus only return ()
is executed and it
bound to ()
, for pure (+1)
, a function is returned, there's no Show
instance for functions in scope, so nothing is printed. However,
Prelude Control.Applicative> :m +Text.Show.Functions
Prelude Control.Applicative Text.Show.Functions> pure (+1)
<function>
it :: Integer -> Integer
Prelude Control.Applicative Text.Show.Functions> it 3
4
it :: Integer
with a Show
instance for functions in scope, it gets printed (not that it's informative), and the function can then be used (the latter is independent of a Show
instance being in scope, of course).