0

I am starting in Haskell and encounter this weird error message when trying to compile a .ghci file in Haskell. I have this very simple code for example:

main = do
    putStrLn "Greetings! What is your name?"
    inpStr <- getLine
    putStrLn $ "Welcome to Haskell, " ++ inpStr ++ "!"

I saved the code in a file called basicio.hs and tried to run ghc basicio.hs Instead of the String I get the following message

<interactive>:2:1: error:
    Variable not in scope: runghc :: t0 -> b0 -> c

<interactive>:2:8: error: Variable not in scope: basicio

I am not sure what's wrong, the command ":load" works fine and find my file.

Jonathan Peil
  • 126
  • 1
  • 7
  • 2
    How did you load the file? What flags did you use to run `ghci`? – Willem Van Onsem Jul 11 '19 at 12:02
  • Well ifor ghci I run it directly without addings any flags after `ghci` in the shell. The command to compile that I have tried was simply `ghc basicio.hs`. – Jonathan Peil Jul 11 '19 at 12:11
  • did you load the multiline statement between `:{` and `:}` ref.: https://stackoverflow.com/questions/8443035/multi-line-commands-in-ghci – Willem Van Onsem Jul 11 '19 at 12:18
  • I did save the code to a file named `basicio.hs` and tried to compile the file. So I guess I don't need the `:{ :}' – Jonathan Peil Jul 11 '19 at 12:21
  • what if you load it with `ghci basicio.hs`. I can not reproduce it if I write `:l basicio.hs` or `:load basicio.hs`. – Willem Van Onsem Jul 11 '19 at 12:23
  • The command `:load basicio.hs` works as expected without any error, although `ghci basicio.hs` returns the same error as in my post. I don't seem to understand where does the problem comes from... – Jonathan Peil Jul 11 '19 at 12:36

1 Answers1

4

This error messages looks like it was generated by typing "runghc basicio" at the GHCi prompt:

GHCi, version 8.6.5: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from ...
> runghc basicio

<interactive>:3:1: error: Variable not in scope: runghc :: t0 -> t

<interactive>:3:8: error: Variable not in scope: basicio
>

However, the runghc command, and the compiler command ghc are both meant to be run directly from the command line.

K. A. Buhr
  • 45,621
  • 3
  • 45
  • 71