2018年在Manjaro Linux上安装Haskell及解决Emacs模式问题
Hey there! Let's work through this Stack and haskell-mode issue you're facing on Manjaro. Arch-based distros can have some quirks with Haskell tooling, especially if you're relying on an older 2014 installation guide—let's get this sorted out step by step.
1. 更新Stack到最新稳定版
The biggest culprit here is likely an outdated Stack version (since 2014, Stack has gone through massive changes that break compatibility with newer haskell-mode versions). The Manjaro repo package might be stale, so let's replace it with the official up-to-date version:
- Run this in your terminal to install the latest Stack:
curl -sSL https://get.haskellstack.org/ | sh - Once installed, verify the version with:
stack --version - Then set up the latest GHC toolchain for Stack:
stack setup
2. 配置Emacs的haskell-mode适配Stack
Next, we need to tell haskell-mode to use Stack's GHCi instead of any system-level Haskell tools. Open your Emacs config file (either ~/.emacs or ~/.emacs.d/init.el) and add these lines:
;; Force haskell-mode to use Stack's GHCi (setq haskell-process-type 'stack-ghci) ;; Specify Stack path (only needed if the script installed it outside your $PATH) (setq haskell-stack-path "/usr/local/bin/stack") ;; Enable handy haskell-mode features (add-hook 'haskell-mode-hook #'haskell-indent-mode) (add-hook 'haskell-mode-hook #'interactive-haskell-mode)
Save the file, then restart Emacs or run M-x eval-buffer to load the new config.
3. 清理冲突的系统级Haskell包
Since Stack manages its own isolated GHC environment, you don't need the system-level Haskell packages you installed from the Manjaro repo. These can cause conflicts, so let's remove them:
sudo pacman -Rs ghc cabal-install
Also, check that your Stack directory has proper permissions (sometimes old installs leave root-owned files):
ls -la ~/.stack
If you see root-owned files, fix them with:sudo chown -R $USER:$USER ~/.stack
4. 测试配置是否正常
Create a simple test file test.hs with:
main = putStrLn "Hello Haskell!"
Open it in Emacs, then run C-c C-l to load it into Stack's GHCi. If you see the GHCi prompt and can run main successfully, you're good to go!
If you still run into errors, check the Messages buffer in Emacs (M-x view-echo-area-messages) for specific details—common issues include misconfigured Stack paths or missing dependencies.
内容的提问来源于stack exchange,提问作者Klorax

