cabal sandbox + haskeline - haskell

cabal sandbox init
cabal install haskeline
... installs successfully ...
ghci
Prelude> :module +System.Console.Haskeline
<no location info>:
Could not find module `System.Console.Haskeline'
ghc-pkg list haskeline
.. not found ..
What do I have to do get haskeline to work with cabal sandbox? If I install haskeline normally (no sandbox) it is fine (ghc-pkg list haskeline -- found it).

Either use cabal repl like Joseph mentioned or you can explicitly pass the package db to the GHCi shell relative to your current working directory.
ghci -no-user-package-db -package-db .cabal-sandbox/*-packages.conf.d YourModule.hs
It's recommended that you just use cabal.

In order to get ghci to use a local sandbox you must (a) set up a my-project.cabal file and (b) use cabal repl.

Related

What is the cabal equivalent of `stack ghci app:exe:executable`?

I've previously used stack ghci app:exe:executable to get a list of any errors in my Haskell project managed via cabal.
However now that I'm not using stack, how would I achieve the above (essentially load all the modules from the executable defined in the cabal project file)?
https://cabal.readthedocs.io/en/latest/nix-local-build.html#cabal-v2-repl
cabal v2-repl executableNameGoesHere

Haskell package installed but not found (Ubuntu) [duplicate]

I installed diagrams, and it seems to be there, but GHCi doesn’t find it. I tried adding the local sandbox to the command line (-package-db), but still no luck.
Any suggestions?
C:\Users\guthrie>
C:\Users\guthrie>cabal install diagrams
Resolving dependencies...
All the requested packages are already installed:
diagrams-1.2
Use --reinstall if you want to reinstall anyway.
I find it in:
C:\Users\guthrie\.cabal-sandbox\i386-windows-ghc-7.6.3-packages.conf.d
(diagrams-1.2, diagrams-contrib, -core, -lib, -svg)
But running: “cabal repl” or using the GHC(i) flag “-package-db=…”
fail to find it:
C:\Users\guthrie>cabal repl
GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :m + Diagrams.Prelude
<no location info>:
Could not find module `Diagrams.Prelude'
It is not a module in the current program, or in any known package.
Prelude>
To clarify; ignoring the cabal invocations, using GHC/i directly, and the program diagramsDemo.hs:
-- http://projects.haskell.org/diagrams/doc/quickstart.html
--
import Diagrams.Prelude
import Diagrams.Backend.SVG.CmdLine
main = mainWith (circle 1 :: Diagram B R2)
Gives:
C:\Users\guthrie\Desktop\xFer\Graphics>ghc --make diagramsDemo.hs
diagramsDemo.hs:7:8:
Could not find module `Diagrams.Backend.SVG.CmdLine'
Use -v to see a list of the files searched for.
C:\Users\guthrie\Desktop\xFer\Graphics>ghc --make diagramsDemo.hs -package-db=C:\Users\guthrie\.cabal-sandbox\i386-windows-ghc-7.6.3-packages.conf.d
diagramsDemo.hs:7:8:
Could not find module `Diagrams.Backend.SVG.CmdLine'
Use -v to see a list of the files searched for.
As bheklilr said, if ghci is started with cabal repl, it will only find packages specified as a dependency in the .cabal file.
However you can start it with cabal exec ghci, then it will find all packages installed in the sandbox.
The same is true for invoking ghc (cabal build vs. cabal exec ghc), but note that if you want to pass flags you have to use --, like in cabal exec ghc -- -O2 Main.hs. Alternatively you can use cabal exec bash and launch ghci or ghc in the new shell.
cabal exec was added with Cabal 1.20.

Cabal install current package into its own .cabal-sandbox/*-packages.conf.d

I have a package named commands. I want to install it into its own sandbox e.g. .cabal-sandbox/x86_64-osx-ghc-7.8.3-packages.conf.d/commands-0.0.0-f3f84f48f42ac74a69ee5fd73512bfd0.conf. currently, there is just one .hi interface file for one module Commands, I don't know how it got there.
I tried cabal install commands, by the logic of "that's how the other packages got there I think", but it fails with unknown package.
I also tried stuff with ghc-pkg like ghc-pkg update commands -f .cabal-sandbox/x86_64-osx-ghc-7.8.3-packages.conf.d but I'm not using them right. ideally, I'd like to do this with cabal.
the last thing I tried was ghc -idist/build/, but it complained about the package names in the interface files being different, command versus main ("... differs from name found in the interface file ..."). and if I faked the executable's package with ghc -package-name commands-0.0.0, the linker complained that it couldn't find the symbol _ZCMain_main_closure, because every executable needs the function main in the module Main in the package main.
I'm sure there's a better way of doing this.
I followed online examples for my cabal file:
$ cat commands.cabal
name: commands
library
exposed-modules: Commands.Types, Commands.Bits
...
the minimal failing code example is just:
$ cat Main.hs
import Commands.Types
main = return ()
in the root project directory.
Context: I need to build my executable with make (not cabal) because it links to foreign code (Objective-C via language-c-inline). my makefile: https://github.com/sboosali/Haskell-DragonNaturallySpeaking/blob/master/Makefile). thus, I have to compile a script explicitly. I don't know how to compile the executable with cabal, but I want cabal to build and test and manage my library.
By putting my package into the sandbox, I will be able to import its modules from the script, by compiling with cabal exec -- ghc. I will also be able to include the script with extra-source-files at least, and know it will work.
Here's what I'd try:
First unregister any previous commands library. Try
ghc-pkg --global unregister commands
Install new commands to your sandbox.
From your sandbox directory, try this:
cabal --enable-shared --disable-documentation --prefix=./ install /path/to/your/library/source
Note the prefix specification.
I nuked it (rm -fr .cabal-sandbox/), reinstalled everything (cabal install --only-dependencies), added itself as a source (cabal sandbox add-source .), installed it (cabal install command). and then make worked. idk...

Persistent modules not found

I'm trying to use http://hackage.haskell.org/package/persistent-1.2.3.0, but after installing it through "cabal install persistent", ghc doesn't find its exposed-modules:
Prelude> import Database.Persist.Types
<no location info>:
Could not find module `Database.Persist.Types'
It is not a module in the current program, or in any known package.
And ghc-pkg works fine:
$ ghc-pkg find-module Database.Persist.Types
/var/lib/ghc/package.conf.d
/home/apsk/.ghc/x86_64-linux-7.6.3/package.conf.d
persistent-1.2.3.0
Am I missing something or is this just a bug with cabal/persistent/ghc? My ghc is 7.6.3, btw.
Also, I've tried with no effect: "ghc-pkg recache"; "ghc-pkg check"; installing previous version; reinstalling with and without "sudo" and/or "--global".
Check that you're not using sandboxes, cabal-dev, hsenv, anything else that can influence ghc in looking for dependencies. Make sure you're using ghc/ghci, and not any wrappers, and that ghc/ghci are not aliased to anything in your shell.
Try to specify the package-db explicitly:
ghci -package-db /home/apsk/.ghc/x86_64-linux-7.6.3/package.conf.d
If you launch ghci with -v, it'll print the (caches of) databases it looks at, like this:
% ghci -v
GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
Glasgow Haskell Compiler, Version 7.6.3, stage 2 booted by GHC version 7.4.2
Using binary package database: /opt/ghc763/lib/ghc-7.6.3/package.conf.d/package.cache
Using binary package database: /home/feuerbach/.ghc/i386-linux-7.6.3/package.conf.d/package.cache
Make sure that the database which has persistent is listed there.
Hopefully helpful to someone. Using ghci -v I looked to see if persistent was there, and saw this:
package persistent-2.0.8-cec952b1a61645f47dbec3b0b0cbcef4 is unusable due to missing or recursive dependencies: aeson-0.8.0.0-1bd8b5254a1dd30c0fe6acc346ad7de7 attoparsec-0.12.1.2-48393fcdbcf426085b696dc4409d9270 conduit-1.2.0.2-39f9cd0430ed7b7f4306899cbeb1ed83 monad-logger-0.3.7.2-3e6a80e9b3adf31497ff04514bdf2919 resource-pool-0.2.3.0-c02186641e7173f72887d5e65a646ac1 scientific-0.3.3.1-13e0eefbd7215e4503420c3d0a6fdb82 unordered-containers-0.2.5.0-147c3bb8f4a2da7d753455e75af30b92
So I looked around on SO (saw this: Haskell Cabal: Mysterious missing or recursive dependencies) but didn't find a great answer. I did find a good one here though:
$ ghc-pkg list Cabal
Which revealed I had 2 goddamn cabals! One in user and one in global. Ugh. So I was able to do ghc-pkg unregister --user Cabal-1.18.1.3 --force to get rid of the old one. Then cabal install cabal automatically went for 1.20, implicitly into user without any flag (the alternate would be --global).
The problem only occurs in GHCi, right? Have you restarted GHCi since installing persistent? (Maybe there's another way to get GHCi to pick up newly installed packages, but I'm not aware of it.

How do i use runhaskell with cabal-dev?

Unfortunately cabal-dev ghci does not work in this project, i get an error:
Loading package download-0.3.2 ... linking ...
ghc: /home/stulli/haskell/ifdl/cabal-dev//lib/download-0.3.2/ghc-7.4.1/HSdownload-0.3.2.o: unknown symbol `stat64'
ghc: unable to load package `download-0.3.2'
So i try runhaskell, but it uses the packages that come installed with cabal instead of cabal-dev and thus fails.
update:
runhaskell produces the same error:
$ runhaskell -isrc:src/test -package-conf=cabal-dev/packages-7.4.1.conf src/test/Test.hs
Test.hs: /home/stulli/haskell/ifdl/cabal-dev//lib/download-0.3.2/ghc-7.4.1/HSdownload-0.3.2.o: unknown symbol `stat64'
Test.hs: Test.hs: unable to load package `download-0.3.2'
cabal-dev install on the other hand works without problems.
You can try something like the next:
runhaskell -package-conf=cabal-dev/packages-7.0.3.conf main.hs
But I think if cabal-dev ghci doesn't work, then runhaskell will not work too. You need to find out what is wrong with download package.
To use runhaskell with cabal sandboxes (cabal >= 1.18), run the command
runhaskell -package-db=.cabal-sandbox/i386-windows-ghc-7.6.3-packages.conf.d <file.hs>
substituting the proper *-packages.conf.d directory for your GHC version.
The cabal-dev setup doesn't work very well for ghci, so it might very well be that it also doesn't work well for runhaskell. Maybe virthualenv will work better for this use case?

Resources