在 nix-shell 中找不到模块

wiz*_*zup 3 haskell nixos nix

可能是什么原因missing module

\n\n
$ nix-shell -p haskellPackages.ghc -p haskellPackages.random\n
Run Code Online (Sandbox Code Playgroud)\n\n

给出以下外壳

\n\n
[nix-shell:~]$ ghci \nGHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help\nLoaded GHCi configuration from /data/works/dotfiles/ghci\nPrelude> import System.Random\n\n<no location info>: error:\n    Could not find module \xe2\x80\x98System.Random\xe2\x80\x99\n    It is not a module in the current program, or in any known package.\n
Run Code Online (Sandbox Code Playgroud)\n\n

Haskell 软件包的安装和使用方法什么?nix

\n\n

我以为nixos.haskellPackages.<package>会自动注册 ghc 但似乎并非如此。

\n\n

重新装上random内壳,还是不行。

\n\n
[nix-shell:~]$ nix-env -iA nixos.haskellPackages.random\ninstalling \xe2\x80\x98random-1.1\xe2\x80\x99\n\n[nix-shell:~]$ ghc-pkg list | grep -i random\n
Run Code Online (Sandbox Code Playgroud)\n

She*_*rsh 5

我不知道这不起作用的原因。但你可以尝试这个命令:

nix-shell -p "haskellPackages.ghcWithPackages (pkgs: with pkgs; [random])"
Run Code Online (Sandbox Code Playgroud)

对我有用。现在ghci看到System.Random包了。

更新:

这篇文章对初学者的冒险确实很有帮助nix + haskell

https://web.archive.org/web/20170910171927/http://alpmestan.com/posts/2017-09-06-quick-haskell-hacking-with-nix.html

  • 此方法仅适用于“ghc”,不适用于“ghc-mod”;`$ nix-shell -p "haskellPackages.ghcWithPackages (self: with self; [随机 ghc-mod])"`; 我对 nixos haskell 系统很困惑。 (2认同)