Confusing ghci error message
$ ghci
GHCi, version 8.6.3: http://www.haskell.org/ghc/ :? for help
Prelude> import qualified Data.Set as S
Prelude S> S.foo
<interactive>:2:1: error:
Not in scope: ‘S.foo’
No module named ‘S’ is imported.
I'm curious why ghci
says No module named 'S' is imported
. I found it very confusing.
I'd have expected it to say one of three things:
Module Data.Set referenced via S does not export foo
Constructor S not in scope
Variable foo not in scope
The first one would be the most informative, but I can see that the second and the third messages might be quite reasonable as well due to the interpretation of dot as composition. But the message No module S is imported
is quite confusing given I just issued import qualified Data.Set as S
.
Indeed, if I put this in a file, the error message is crystal clear:
$ cat a.hs
import qualified Data.Set as S
bar = S.foo
$ ghci a.hs
GHCi, version 8.6.3: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( a.hs, interpreted )
a.hs:3:7: error:
Not in scope: ‘S.foo’
Module ‘Data.Set’ does not export ‘foo’.
|
3 | bar = S.foo
| ^^^^^
Failed, no modules loaded.
I'm curious why there's a difference between these two scenarios.