首页 > 解决方案 > 无法加载模块“System.Random”

问题描述

我无法添加 System.Random 模块来使用它我的源 haskell 文件。

import System.Random

这是堆栈 ghc 产生的错误:

/Users/admin1/Haskell/PROJECTS/L4/src/Lib4.hs:32:1: error:
Could not load module ‘System.Random’
It is a member of the hidden package ‘random-1.1’.
You can run ‘:set -package random’ to expose it.
(Note: this unloads all the modules in the current scope.)
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
   |
32 | import System.Random
   | ^^^^^^^^^^^^^^^^^^^^
Failed, five modules loaded.

非常感谢您提前。PS 我正在使用 Stack 和 GHC 版本:版本 2.3.1,Git 版本 x86_64 hpack-0.33.0,Mac OSX 上的 ghc-8.8.3

标签: haskell

解决方案


正如错误所说:

It is a member of the hidden package ‘random-1.1’.

这可能意味着您没有在 中列出它build-depends,因此它不会暴露给您的模块。

您可以更改.cabal文件并添加它,例如:

-- project.cabal file
-- …

executable …
  -- …
  build-depends:
      base >= 4.7 && < 5
    , random >= 1.1
    -- ,  …

推荐阅读