error-messages icon indicating copy to clipboard operation
error-messages copied to clipboard

"In a stmt of an interactive GHCi command: print it"

Open monoidal opened this issue 3 years ago • 2 comments

ghci> data T = MkT
ghci> MkT

<interactive>:2:1: error:
    • No instance for (Show T) arising from a use of ‘print’
    • In a stmt of an interactive GHCi command: print it
ghci> 0#

<interactive>:3:1: error:
    • Couldn't match a lifted type with an unlifted type
      When matching types
        a0 :: *
        GHC.Prim.Int# :: TYPE 'GHC.Types.IntRep
    • In the first argument of ‘print’, namely ‘it’
      In a stmt of an interactive GHCi command: print it

The part stmt of an interactive GHCi command: print it is confusing.

It corresponds to what's happening under the hood - it will change if you set -fno-it and/or -interactive-print <fun>, but I still think it's not good enough. This error is often seen by beginners.

monoidal avatar Nov 17 '22 18:11 monoidal

Similarly, printing functions in GHCI also creates confusing error messages:

Reproduction

λ> add x y = x + y
add :: Num a => a -> a -> a
λ> add

<interactive>:8:1: error:
    • No instance for (Show (Integer -> Integer -> Integer))
        arising from a use of ‘print’
        (maybe you haven't applied a function to enough arguments?)
    • In a stmt of an interactive GHCi command: print it

Suggestion

suggest the programmer to import Text.Show.Functions:

λ> add x y = x + y
add :: Num a => a -> a -> a
λ> add

<interactive>:8:1: error:
    • No instance for (Show (Integer -> Integer -> Integer))
        arising from a use of ‘print’
        (maybe you haven't applied a function to enough arguments?)
    • In a stmt of an interactive GHCi command: print it
	• Maybe you want to interactively print a type of function in GHCi?
		if so, type 'import Text.Show.Functions', to be able to:

		λ> add
		<function>
		it :: Num a => a -> a -> a

scarf005 avatar Jul 11 '23 11:07 scarf005