Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
monoidal opened this issue Nov 17, 2022 · 1 comment
Open

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

monoidal opened this issue Nov 17, 2022 · 1 comment

Comments

@monoidal
Copy link
Member

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.

@scarf005
Copy link

scarf005 commented Jul 11, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants