I really like how I can interactively load packages and experiment at will in Common Lisp, and would like to get a similar workflow in Haskell. I've settled on Cabal (v184.108.40.206 - new command set by default) because it's less opinionated than Stack and has access to all of Hackage - I'm more interested in Haskell for experimentation than stable tooling for production code. I currently have haskell-mode, flycheck (globally), and lsp-haskell set up, with ghcide as an LSP backend.
I don't expect Haskell to hotswap code a la Lisp or Erlang (it seems at odds with the notion of a stateless, self-consistent denotation of a correct program), but I would like to import modules without closing the project, editing the Cabal file, and restarting it.
My first go at using haskell-mode's built-in module-loading tools resulted in this error, but it can't be that common because I haven't found any other references to it online.
The second time (after making some other changes like those suggested here), it let me add the external packages to the Cabal file and said it reloaded the process, but Flycheck still says the packages are hidden. Weirdly enough, this persists even after I close and reload the project, even when I kill both the project process and the LSP process before reopening.
hasky-cabal didn't help, and it's shelved for a reason; flycheck-haskell didn't add much other than a weird, inconsequential error about exiting with error code 0. Having to restart everything when Emacs is my window manager is mildly inconvenient, to say the least.
Am I missing something about how to load packages into Haskell from within Emacs? How can I experiment with dependencies without exiting the editor? I'm new to Haskell, so some pointers would be much appreciated.
So no one has to guess when I might be making a dumb mistake in the configuration, my setup for various parts:
(use-package lsp-mode :custom (lsp-prefer-flymake nil) :hook (haskell-mode . lsp)) (use-package lsp-ui :after lsp-mode :hook (lsp-mode . lsp-ui-mode) :bind (:map lsp-ui-mode-map ([remap xref-find-definitions] . lsp-ui-peek-find-definitions) ([remap xref-find-references] . lsp-ui-peek-find-references) ([remap imenu] . lsp-ui-imenu)) :config (lsp-ui-flycheck-enable t)) (use-package company-lsp :custom (company-lsp-async t) (company-lsp-cache-candidates 'auto) (company-lsp-enable-snippet t) (company-lsp-enable-recompletion t) :after lsp-mode :config (push 'company-lsp company-backends)) (use-package lsp-ivy :after lsp-mode) (use-package lsp-haskell :after (haskell-mode lsp-mode) :custom (lsp-haskell-process-path-hie "ghcide") (lsp-haskell-process-args-hie '()))
(use-package haskell-mode :defer t :custom (haskell-hoogle-command "hoogle") (haskell-process-type 'auto) (haskell-stylish-on-save t) (haskell-tags-on-save t) :init (setq-default flycheck-disabled-checkers '(haskell-stack-ghc)) :hook (haskell-mode . interactive-haskell-mode) (haskell-mode . turn-on-haskell-indent) (haskell-mode . turn-on-haskell-doc-mode) (haskell-mode . haskell-auto-insert-module-template) :bind (:map haskell-mode-map ("C-c h" . haskell-hoogle) ("C-c n" . haskell-navigate-imports) ("C-c C-c" . haskell-compile)) (:map haskell-cabal-mode-map ("C-c C-c" . haskell-compile)) :mode ("\\.hs\\'" . haskell-mode) :config (push '(haskell-interactive-mode :position right :tail t) popwin:special-display-config)) (use-package hasklig-mode :defer t :hook (haskell-mode))
I accidentally found out that the error is fixed when I cd to the directory and "cabal install varying --lib", which symlinks it. Earlier, I had run into trouble with installing a package globally and pulling it into a project without fully reinstalling it, so this was somewhat unexpected. This is how I initially expected Cabal's Nix-style local builds to work, which is nice. Restarting the LSP workspace afterwards got rid of the message.
This works for now, but a more editor-integrated approach would be nice!