Search code examples
haskellcabal

Trouble with Haskell package (newsynth)


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


Solution

  • 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.