Update Intero flycheck after changing cabal file - haskell

I am using Intero under emacs to edit my new Haskell project. I added an import to a third-party library to my code to see if Intero would automatically add the necessary dependency, but it didn't. So I edited the .cabal file manually to add the necessary dependency. Now what do I do - short of restarting emacs?
I've tried running cabal install --dependencies-only; cabal configure at the command line and they ran successfully, but the flycheck buffer still shows an error.

All that is necessary is to run
M-x intero-restart
in emacs.
Intero uses stack which has its own private sandbox for each package you are developing, so cabal install --dependencies-only isn't needed or useful.

Related

cabal doesn't seem to register installed packages [duplicate]

I'm a Haskell newcomer and have Haskell installed on my (Mac) machine; I'm trying to use newsynth (https://www.mathstat.dal.ca/~selinger/newsynth/, http://hackage.haskell.org/package/newsynth). In my terminal in the same place where I installed Haskell (home directory) I ran the command cabal install newsynth as suggested by the package authors. However, I can't figure out how to actually access anything from the package from the command line, let alone within a particular file.
In GHCi Prelude, I tried running commands of the form import Quantum and import Quantum.Synthesis.Diophantine but always get an error message. (e.g. in contrast, import Data.Complex works just fine.)
(I'm sure I'm missing something pretty obvious, but I only began with Haskell on Monday, and need to spin up some newsynth code by next week, which is why I'm not starting from the ground up.) Any advice on (1) how to run newsynth's functions from GHCi and (2) how to incorporate them into .hs files would be greatly appreciated. Thanks!
Edit: cabal --version returns
cabal-install version 3.2.0.0 (newline) compiled using version 3.2.0.0 of the Cabal library
Quoting a comment:
[cabal --version] returns: cabal-install version 3.2.0.0 (newline) compiled using version 3.2.0.0 of the Cabal library
It seems the installation instructions in the project page you linked to haven't been updated for cabal-install 3+ yet (in fairness, cabal-install 3 is relatively recent). In any case:
If all you want is running ghci and trying those modules out, with no strings attached, use cabal install --lib newsynth. That will make the newsynth package available in GHC's global environment (see the cabal install entry in the Cabal User Guide for further information).
Since you ultimately want to use the package in the code you'll have to write, though, my recommendation is using cabal init to create a new project for your code. Then, edit the .cabal file of the project to add newsynth to its build-depends section, and that's it: the package will be installed (if it isn't already) and made available in the context of your project the next time you do a cabal build to build the project, or a cabal repl to run GHCi in the context of your project. In that case, there is no need to use the cabal install command at all.

Intero always installs isolated GHC

I opened a Haskell file on a fresh installation of Emacs & Intero. While booting up, intero is trying to install an isolated GHC. This even though my project has stack.yaml which has system-ghc: true. Running stack install in this directory does not reinstall GHC.
Is there any way to make Intero use system ghc instead of reinstalling?
The emacs mode is probably trying to install the intero binary outside the context of your project, to ensure that the intero binary isn't affected by the project's library choices. I'm guessing that setting system-ghc: true in your user config file (~/.stack/config.yaml) instead will solve this problem.
You may also want to set install-ghc: false to disable automatic GHC installation.

Synastic errors - Vim, Stack, Haskell development

I am using stack for my Haskell development and Syntastic for my error checking when editing in Vim. I have not installed the haskell-platform, instead, I use a stack build --install-ghc to get my environment up and running using the supported GHC, cabal and lts packages.
Normally, I use a cabal sandbox and syntastic works well with this. I see when I do a let g:syntastic_debug=3 in Vim, syntastic runs a cabal configure which checks if the project dependencies are installed and then goes ahead and does some hlint, hdevtools and ghc-mod magic to give me some warnings and/or error messages.
Now, here is my problem. Since my cabal setup (installed from stack) doesn't know about my dependencies installed at .stack-work or .stack (not sure), it complains that I am missing necessary packages and blows up when syntastic runs in my Vim instance.
Trying to run a stack exec -- cabal configure returns the following error:
Use of GHC's environment variable GHC_PACKAGE_PATH is incompatible with Cabal. use the flag --package-db to specify a package database (it can be used multiple times).
I haven't found out how to pass the --package-db option with the correct database. Nothing seems to work there.
So, the quetion - will successfully running a stack exec -- cabal configure, avoiding the GHC_PACKAGE_PATH issue get me to a working setup? Can anyone give me some direction here?
hdevtools works. See here: http://seanhess.github.io/2015/08/05/practical-haskell-editors.html
I'm planning on keeping that up to date as new tools come out (like stack-ide).
This blogpost gives a nice introduction as well. Things change quickly in the haskell world and ghc-mod seems to be working well with stack now. The setup from the post requires neovim though.
The setup from the post worked perfectly fine for me and found all dependencies within the current stack project.

Cabal-installed Modules won't import

There are several things I'm confused about here, so I'll try to explain each of them as clearly as I can.
I've been trying to install the diagrams package for haskell, using cabal. I've seen it suggested to install packages using sandboxes, so that's what I did. Something that's not clear to me is exactly what a sandbox is - I understand that I can initialise one with cabal sandbox init and install packages inside of it with cabal install, but I don't see how to use those packages once they're installed.
I then tried to compile a test-script using ghc, which resulted in the following error:
diagramstutorial.lhs:3:10:
Could not find module 'Diagrams.Prelude'
Use -v to see a list of the files searched for.
With a similar error for another module that the script was supposed to load. These modules are definitely both included in the diagrams package, and cabal seems happy that the package is installed correctly. I expect there's something simple I just don't understand, but I don't know what it is.
I typed ghc --make diagramstutorial.lhs to compile it
That will make GHC use the regular user package database (that is, not the sandbox one). Use cabal exec -- ghc --make diagramstutorial.lhs instead, so that GHC runs in the context of your sandbox.
You can also use GHCi within the sandbox with cabal repl. And naturally, if/when you start preparing a cabal package, all cabal commands (cabal build, etc.) will use the sandbox if you are within its directory.
Something that's not clear to me is exactly what a sandbox is
A set of packages with an accompanying database local to the directory. Beyond the cabal.sandbox.config configuration file there is also a hidden directory .cabal-sandbox, in which diagrams and the other packages you installed lie.
Find the sandbox directory, and locate the packages.conf.d file.
For example, /home/user/.cabal-sandbox/x86_64-linux-ghc-7.8.4-packages.conf.d
Rerun your GHC commands with the package-db flag:
ghci -package-db /home/user/.cabal-sandbox/x86_64-linux-ghc-7.8.4-packages.conf.d --make diagramstutorial.lhs
Everything should now work

Possible to ensure that profiling libraries are installed when installing GHC 7.8?

I'm going to install GHC on a fresh copy of Ubuntu and I'm wondering: How can I ensure that profiling libraries are installed for the core libraries (e.g., text, unordered-containers)?
I'm aware of the changing the profiling option in cabal's .config file but my understanding is that this only ensures that profiling libraries are installed for those packages that I install AFTER setting up cabal (see italicized text in update below).
(I inadvertently blew up my Ubuntu vbox last night as a result of trying to retroactively install profiling libraries for installed GHC packages. It led to the existing packages not working, which led to me trying to uninstall GHC, which led to...KABOOM!)
UPDATE:
I've installed GHC and am now at the point where I'm about to install cabal. I've confirmed my suspicion that I'm facing a "chicken-and-an-egg" dilemma: In order to get the initial cabal config file (in which I can set profiling option as True), I need to install cabal. However, installing cabal results in the installation of core packages (e.g., text, unordered-containers) BEFORE I get a chance to make the change in the cabal config file.
SOLVED:
As per Daniel Wagner's suggestion (thanks!), I made a couple of modifications to the bootstrap.sh script file (I unfortunately didn't have my old cabal or I would've followed his other suggestion). As reference for future readers, the beginning of my bootstrap.sh file looked like this (after the changes):
#VERBOSE
DEFAULT_CONFIGURE_OPTS="--enable-library-profiling --enable-shared"
EXTRA_CONFIGURE_OPTS=${EXTRA_CONFIGURE_OPTS-$DEFAULT_CONFIGURE_OPTS}
#EXTRA_CONFIGURE_OPTS
#EXTRA_BUILD_OPTS
#EXTRA_INSTALL_OPTS
The preferred solution is to install cabal-install via your package manager. If you have an old version of cabal-install in your package manager, you can then use the old version to install the new version with a config in place, or even specify profiling directly on the command line via cabal install cabal-install --enable-library-profiling.
An alternate solution if you plan to install cabal-install via its bootstrap.sh script is to use the environment variables it provides for configuration. There are four, notated at the top of bootstrap.sh; the relevant one is EXTRA_CONFIGURE_OPTS, which contents get passed to the configure step of each package's Setup command. So something like this ought to do the trick (though I haven't tested it):
EXTRA_CONFIGURE_OPTS=--enable-library-profiling ./bootstrap.sh

Resources