ghc 抱怨“找不到模块‘Monad’”

Ale*_*ong -2 haskell

我一直想尝试使用 Haskell 和 Scheme,所以我决定通读“在 48 小时内为自己编写一个方案”一书来探索两者。

我刚刚遇到了Monad模块似乎丢失的第一个障碍。我试过运行它,ghci结果似乎是一样的。

我的环境是 OSX 10.15.2 上的 ghc 8.8.1。

% brew info ghc ghc: stable 8.8.1 (bottled), HEAD Glorious Glasgow
Haskell Compilation System https://haskell.org/ghc/
/usr/local/Cellar/ghc/8.8.1 (6,813 files, 1.5GB) *
Run Code Online (Sandbox Code Playgroud)

这是最小的可重现文件:

% cat hello.hs
module Main where
import Monad
import System.Environment

main :: IO ()
main = do
  putStrLn ("Hello")
Run Code Online (Sandbox Code Playgroud)

这是编译错误:

ghc hello.hs
[1 of 1] Compiling Main             ( hello.hs, hello.o )

hello.hs:2:1: error:
    Could not find module ‘Monad’
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
2 | import Monad
  | ^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)

任何提示?

亚历克斯

Fil*_*und 6

你的意思是导入 Control.Monad 吗?

编译缩小的程序不需要任何导入,因为您需要的一切都已经通过 Prelude 模块隐式导入,但也许您的整个程序需要比 Prelude 更多的依赖项。