首页 > 解决方案 > ghc 抱怨“找不到模块‘Monad’”

问题描述

我一直想玩 Haskell 和 Scheme,所以我决定通读《在 48 小时内为自己编写一个 Scheme》一书来探索这两者。

我刚刚遇到了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) *

这是最小的可重现文件:

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

main :: IO ()
main = do
  putStrLn ("Hello")

这是编译错误:

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
  | ^^^^^^^^^^^^

有什么提示吗?

亚历克斯

标签: haskell

解决方案


您是要导入 Control.Monad 吗?

编译缩小的程序不需要任何导入,因为您需要的所有内容都已通过 Prelude 模块隐式导入,但您的整个程序可能需要比 Prelude 更多的依赖项。


推荐阅读