You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GHC 8.4.2无法导入System.Random模块的原因排查求助

Why GHC 8.4.2 Can’t Find System.Random

Great question—this is a common gotcha when moving between GHC versions, especially from older Ubuntu packages to newer PPAs. Let’s break down the root causes and fixes:

1. GHC 8.4+ Doesn’t Include random by Default

Starting with GHC 8.4, the random package (home to System.Random) was removed from the default set of packages that GHC loads automatically. Ubuntu’s official GHC 8.0.2 package bundles or depends on this package out of the box, which is why it works without extra steps.

Quick Fix: When compiling your BurgerKing.hs with GHC 8.4.2, explicitly tell GHC to include the random package:

ghc-8.4.2 -package random BurgerKing.hs

If you’re using your symbolic link, substitute it in place of ghc-8.4.2 in the command above.

2. The random Package Isn’t Installed for GHC 8.4.2

If the command above still throws an error, the random package might not be present in GHC 8.4.2’s package database. Since you have cabal-install-2.2, use it to install the package specifically for this GHC version:

cabal install random --ghc=/usr/bin/ghc-8.4.2

This will add random to GHC 8.4.2’s available modules, so it can find System.Random without needing the -package flag every time.

Manual symlinks can sometimes skip important environment variables that GHC uses to locate its package database. Instead of a symlink, use Ubuntu’s update-alternatives tool to manage your GHC versions properly:

sudo update-alternatives --install /usr/bin/ghc ghc /usr/bin/ghc-8.4.2 100
sudo update-alternatives --config ghc

This ensures that when you run ghc, it uses the correct paths and environment for your 8.4.2 installation.

4. PPA Dependencies Might Be Missing

Occasionally, third-party PPAs don’t pull in all required dependencies automatically. Try reinstalling GHC 8.4.2 to make sure all core packages are present:

sudo apt-get purge ghc-8.4.2 cabal-install-2.2
sudo apt-get update
sudo apt-get install ghc-8.4.2 cabal-install-2.2

Then run the Cabal install command for random again to cover any gaps.

After trying these steps, your GHC 8.4.2 should compile BurgerKing.hs without issues.

内容的提问来源于stack exchange,提问作者Dannyu NDos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:20:50