我刚开始学习 Haskell。预加载模块被描述为默认模块:The Prelude: a standard module. The Prelude is imported by default into all Haskell modules。但这并没有解释为什么各种文档中在 REPL 中都有“Prelude”前缀。
我已经通过 Chocolatey 安装了 mingw 版本。我的 REPL 显示 "ghci" 作为前缀,而不是 "Prelude"。 点击此处。
为什么前缀不同,交互式编译器中的“Prelude”是什么意思?
Prelude>
我已经通过 Chocolatey 安装了 mingw 版本。我的 REPL 显示 "ghci" 作为前缀,而不是 "Prelude"。 点击此处。
GHCi, version 9.2.1: https://www.haskell.org/ghc/ :? for help
ghci>
预备模块已加载:
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
...
为什么前缀不同,交互式编译器中的“Prelude”是什么意思?
import Data.List
,那么命令行就会显示为Prelude Data.List>
。它列出了当前已经加载了哪些模块。 - Willem Van OnsemPrelude
。只有当您传递-XNoImplicitPrelude
标志时,它才不会加载预定义模块。它更改为ghci>
并不意味着 Prelude 不再加载,它只是意味着它们不再列出已加载的模块,如果您加载了 20 个或更多的模块,则通常不太方便。 - Willem Van Onsem