命令 "ghc" 返回不在范围内的变量

Command "ghc" returning Variable not in scope

我从 Haskell 开始,在 Haskell 中尝试编译 .ghci 文件时遇到了这个奇怪的错误消息。例如,我有这个非常简单的代码:

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

我将代码保存在名为 basicio.hs 的文件中并尝试 运行 ghc basicio.hs 我收到以下消息而不是字符串

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

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

我不确定出了什么问题,命令“:load”工作正常并找到我的文件。

此错误消息看起来像是在 GHCi 提示符下键入“runghc basicio”生成的:

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
>

然而,runghc 命令和编译器命令 ghc 都意味着 运行 直接来自命令行。