GHCi 中的"Prelude"前缀是什么意思?



我刚刚开始学习Haskell。前奏曲被描述为默认模块:

前奏曲:一个标准模块。Prelude默认导入所有Haskell模块

但这并不能解释为什么各种文档都有";前奏曲"作为REPL:中的前缀

Prelude>

我已经通过Chocolatey安装了mingw版本,我的REPL显示";ghci";作为前缀;前奏曲":

GHCi, version 9.2.1: https://www.haskell.org/ghc/  :? for help
ghci>

Prelude模块通过以下方式加载:

GHCi, version 9.2.1: https://www.haskell.org/ghc/  :? for help
ghci> :browse! Prelude
-- imported via Prelude
(!!) :: [a] -> Int -> a
($) :: (a -> b) -> a -> b
...

为什么前缀不同;前奏曲"交互式编译器中的平均值?

但这并不能解释为什么各种文档都有"前奏曲"作为REPL中的前缀。

自ghci-9.0以来,它已更改并显示ghci>提示。

在ghci-9.0之前,提示显示已加载的模块。例如,如果导入模块Data.List,它会将提示更改为:

$ ghci-8.6.5
GHCi, version 8.6.5: http://www.haskell.org/ghc/  :? for help
Prelude> import Data.List
Prelude Data.List>

如果我们不通过指定-XNoImplicitPrelude标志来加载Prelude,我们得到:

$ ghci-8.6.5 -XNoImplicitPrelude
GHCi, version 8.6.5: http://www.haskell.org/ghc/  :? for help
>

从ghci-9.0开始,它显示ghci>作为提示。通常,如果你必须处理很多模块,提示会很长,因此使用GHCi很不方便。

您可以使用:set prompt "someprompt> "将提示设置为其他内容,例如:

$ ghci                                                                                                                                                                                      
GHCi, version 9.0.1: https://www.haskell.org/ghc/  :? for help
ghci> :set prompt "someprompt> "
someprompt> 

提示有一些特殊的序列来显示一些信息,正如@pedrofurla所说。如果您希望在较新版本的GHCi中恢复旧行为,则将提示设置为%s>(对于多行提示也执行:set prompt-cont "%s| "(:

$ ghci
GHCi, version 9.0.1: https://www.haskell.org/ghc/  :? for help
ghci> :set prompt "%s> "
Prelude> import Data.List
Prelude Data.List> 

如果您希望对提示的更改持续到新的GHCi会话中,则将该命令放入~/.ghci中(如果不存在,则创建该命令(。

最新更新