diff options
author | Tom Smeding <t.j.smeding@uu.nl> | 2025-03-03 16:02:24 +0100 |
---|---|---|
committer | Tom Smeding <t.j.smeding@uu.nl> | 2025-03-03 16:02:24 +0100 |
commit | 9fa67dd485ba033c0adfdfe1ef9265a066a2caff (patch) | |
tree | b044ba933485176491c79a6d6c40db5c99b80ece /haskell/cabal-lib.html | |
parent | a5e5452dffd34837ebb228244edefbcb5df1b94f (diff) |
Diffstat (limited to 'haskell/cabal-lib.html')
-rw-r--r-- | haskell/cabal-lib.html | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/haskell/cabal-lib.html b/haskell/cabal-lib.html index 4008c82..281d56b 100644 --- a/haskell/cabal-lib.html +++ b/haskell/cabal-lib.html @@ -1,5 +1,5 @@ <h2>About <code>cabal install --lib</code></h2> -<p><strong>TL;DR: Don't use it, add the library to your <code><em>package-name</em>.cabal</code> or <code>package.yaml</code> instead, or use a <a href="https://cabal.readthedocs.io/en/3.10/getting-started.html#run-a-single-file-haskell-script">cabal script</a>. After you learn more about the downsides, you can reconsider. See the "What to do instead" section below.</strong></p> +<p><strong>TL;DR: Don't use it, add the library to your <code><em>package-name</em>.cabal</code> or <code>package.yaml</code> instead, or use a <a href="https://cabal.readthedocs.io/en/3.10/getting-started.html#run-a-single-file-haskell-script">cabal script</a>, or use <code>cabal repl -b</code>. After you learn more about the downsides, you can reconsider. See the "What to do instead" section below.</strong></p> <hr /> <p>Suppose you are new to Haskell, or at least new to the current (2023) Haskell tooling, and would like to install a program written in Haskell. For example, say you would like to install a Haskell formatter, say <code>fourmolu</code>, and find that installing Haskell packages uses a tool called <code>cabal</code>. @@ -100,7 +100,14 @@ This is in <code>~/.ghc/<em>architecture</em>-<em>OS</em>-<em>ghcversion</em>/en <p>As mentioned, the compiled packages are still around (in <code>~/.cabal/store/ghc-<em>version</em>/</code>), but removing those is tricky -- do not try it, cabal likes to maintain its own consistent set of packages in the "store". Removing the entire store folder for a particular GHC version is safe, however -- even though this does of course mean that you may need to recompile a lot of things later. :)</p> <h2>What to do instead</h2> -<p>Create a project! +<p>If you just wanted a <code>ghci</code> session with some libraries in scope, use e.g. <code>cabal repl -b parsec -b time</code>. +(<code>-b A</code> is short for <code>--build-depends=A</code>.) +This will build those packages, if necessary, and then start a <code>ghci</code> session with those packages in scope.</p> +<p>If you want something slightly more permanent than a single <code>ghci</code> session, you can make a <em>cabal script</em>. +This allows you to effectively make a self-contained project inside a single Haskell file. +You specify the dependencies in a special comment block at the top of the file. +See <a href="https://cabal.readthedocs.io/en/3.10/getting-started.html#run-a-single-file-haskell-script">the documentation</a> for more details.</p> +<p>If you want more than that: create a project! The intended mode of operation of the modern Haskell tooling, that is <code>cabal</code> or <code>stack</code>, is to always work inside of a <em>project</em>. Often, "project" basically means "package", but you can have projects with multiple packages in them (using a <code>cabal.project</code> file, see <a href="https://cabal.readthedocs.io/en/3.10/cabal-project.html">the docs</a>).</p> <p>Creating a package is easily done using <code>cabal init --simple</code> inside a fresh directory. @@ -114,7 +121,4 @@ A package (a single thing in the package repository, should you decide to upload <strong><code>cabal</code> will automatically ensure that a consistent set of versions is compiled and made available, if at all possible.</strong> You can also add <a href="https://cabal.readthedocs.io/en/3.10/cabal-package.html#pkg-field-build-depends">version bounds</a> to your dependencies if you want to apply some proper software engineering principles.</p> <p>(If you want to use <code>stack</code> instead of <code>cabal</code>, try <a href="https://docs.haskellstack.org/en/stable/GUIDE/">their getting started guide</a>.)</p> -<h3>An even lighter-weight alternative</h3> -<p>An alternative to creating a project is to make a <em>cabal script</em>: this allows you to effectively make a self-contained project inside a single Haskell file. -You specify the dependencies in a special comment block at the top of the file. -See <a href="https://cabal.readthedocs.io/en/3.10/getting-started.html#run-a-single-file-haskell-script">the documentation</a> for more details.</p> +<p><em>Edited 2025-03-03 to include <code>cabal repl</code> as an alternative.</em></p> |