- Как установить haskell-platform в Ubuntu / Debian
- Установка:
- Подробная информация о пакете:
- Зависимости:
- Install/upgrade¶
- Windows¶
- Manual download¶
- macOS¶
- Installer script¶
- Manual download¶
- Using Homebrew¶
- Notes¶
- Ubuntu¶
- Debian¶
- CentOS / Red Hat / Amazon Linux¶
- Fedora¶
- openSUSE / SUSE Linux Enterprise¶
- Arch Linux¶
- NixOS¶
- Linux (generic)¶
- Installer script¶
- Manual download¶
- Shell auto-completion¶
- China-based users¶
- Using an http proxy¶
- Upgrade¶
- Install Older Versions¶
- Haskell
- Contents
- Installation
- Configuration
- Invoking GHC directly
- Configuring Cabal for dynamic linking
- Configuring Stack for dynamic linking
- Package management
- Cabal
- Installing packages
- Removing packages
- Stack
- Installing packages
- Removing packages
- Development tools
- Tools
- haskell-language-server
- ghcid
- hoogle
- Linters
- hlint
- weeder
- Formatters
- Editors
- Visual Studio Code
- IntelliJ IDEA
- Emacs
- Alternate installations
- ghcup
- Stack
- Tips and tricks
- Static linking
- Static global package database
- ghc-pristine
- cabal-static
- stack-static
- hpack-static-bin
- ghcup
Как установить haskell-platform в Ubuntu / Debian
Установка:
Для установки haskell-platform в Ubuntu / Linux Mint / Debian, введите в Терминал :
Подробная информация о пакете:
Стандартные библиотеки и инструменты Haskell
Зависимости:
Генератор лексического анализатора для Haskell
Интерфейс командной строки для Cabal и Hackage
Система компиляции Glasgow Haskell
Генератор Parser для Haskell
Программа Haskell для обработки кода Haskell
Запускать операции ввода-вывода асинхронно и ждать их результатов
Быстрое разборчивание комбинаторов для байтов
Сравнение строк без учета регистра
Графовая библиотека Haskell для GHC
Необработанная привязка для графической системы OpenGL
Haskell GLUT для GHC
Класс для типов, которые могут быть преобразованы в хэш-значение
Модуль Haskell для управления источником Haskell
Haskell html библиотека для GHC
Библиотеки GHC для клиентской библиотеки Haskell HTTP
Структурная схема тестирования Haskell для GHC
Библиотека трансформаторов монашеской монархии для GHC
Низкоуровневая сетевая библиотека Haskell
Связывание Haskell OpenGL для GHC
Необработанная привязка для графической системы OpenGL
Библиотека параллельного программирования Haskell для GHC
Библиотека комбинаторного анализатора Haskell для GHC
Упаковщики для примитивных операций
Библиотека автоматического тестирования Haskell для GHC
Генератор случайных чисел для Haskell
Библиотека GHC, предоставляющая API для регулярных выражений
Библиотека GHC, предоставляющая старый интерфейс Text.Regex
Библиотека GHC для регулярного выражения POSIX для regex-base
Библиотека Haskell для расщепления списков
Библиотека программной памяти Haskell для GHC
Общая библиотека программирования для Haskell
Эффективный упакованный тип текста Unicode для Haskell
Эффективные типы контейнеров на основе хеширования
Эффективные массивы для Haskell
Сжатие и декомпрессия в форматах gzip и zlib
Источник
Install/upgrade¶
For common Un*x operating systems (including macOS), all you need to do is run:
Note that this script will ask for root access using sudo in order to use your platform’s package manager to install dependencies and to install to /usr/local/bin . If you prefer more control, follow the manual installation instructions for your platform below.
Binaries for other operating systems are listed below, and available on the GitHub release page. For the future, we are open to supporting more OSes (to request one, please submit an issue).
Binary packages are signed with this signing key.
If you are writing a script that needs to download the latest binary, you can use URLs like https://get.haskellstack.org/stable/
. (e.g. https://get.haskellstack.org/stable/linux-x86_64.tar.gz) that always point to the latest stable release.
Windows¶
We recommend installing to the default location with these installers, as that will make stack install and stack upgrade work correctly out of the box.
If in doubt: you should prefer the 64-bit installer.
You may see a «Windows Defender SmartScreen prevented an unrecognized app from starting» warning when you try to run the installer. If so, click on More info, and then click on the Run anyway button that appears.
Manual download¶
Download the latest release:
Unpack the archive and place stack.exe somewhere on your %PATH% (see Path section below) and you can then run stack on the command line.
Now you can run stack from the terminal.
macOS¶
We generally test on the current version of macOS and do our best to keep it compatible with the three most recent major versions. Stack may also work on older versions (YMMV).
Installer script¶
Manual download¶
- Download the latest release:
- macOS 64-bit
- Extract the archive and place stack somewhere on your $PATH (see Path section below)
- Now you can run stack from the terminal.
Using Homebrew¶
If you have the popular brew tool installed, you can just do:
- The Homebrew formula and bottles are unofficial and lag slightly behind new Stack releases, but tend to be updated within a day or two.
- Normally, Homebrew will install from a pre-built binary (aka «pour from a bottle»), but if brew starts trying to build everything from source (which will take hours), see their FAQ on the topic.
Notes¶
After installation, running stack setup might fail with configure: error: cannot run C compiled programs. in which case you should run:
Starting with macOs 10.14 (Mojave) running xcode-select —install might not be enough. You will need to install additional headers by running:
If you are on OS X 10.11 («El Capitan») and encounter either of these problems, see the linked FAQ entries:
If you are on OS X 10.12 («Sierra») and encounter GHC panic while building, see this issue
Ubuntu¶
There is also a Ubuntu package for Ubuntu 16.10 and up, but the distribution’s Stack version lags behind, so we recommend running stack upgrade —binary-only after installing it. For older stack versions which do not support —binary-only , just stack upgrade may work too. The version in Ubuntu 16.04 is too old to upgrade successfully, and so in that case stack should be installed from a release tarball.
Debian¶
There is also a Debian package for Stretch and up, but the distribution’s Stack version lags behind, so running stack upgrade —binary-only is recommended after installing it. For older stack versions which do not support —binary-only , just stack upgrade may work too.
CentOS / Red Hat / Amazon Linux¶
There is also an unofficial Copr repo. Note that this Stack version may lag behind, so we recommend running stack upgrade after installing it.
Fedora¶
Fedora includes builds of stack, but the version may lag behind, so we recommend running stack upgrade after installing it.
openSUSE / SUSE Linux Enterprise¶
There is also an unofficial SUSE package. Note that this Stack version may lag behind, so we recommend running stack upgrade after installing it. To install it:
Add the appropriate OBS repository:
all needed is in distribution
SUSE Linux Enterprise 12
Arch Linux¶
There is an official package in the Arch community repository. So you can install it by simply doing:
Note that this version may slightly lag behind, but it should be updated within the day. The package is also always rebuilt and updated when one of its dependencies gets an update.
In order to use stack setup with older versions of GHC or on a 32-bit system, you may need the ncurses5-compat-libs AUR package installed. If this package is not installed, Stack may not be able to install older ( haskell-stack-tool package from there.
NixOS¶
Users who follow the nixos-unstable channel or the Nixpkgs master branch can install the latest stack release into their profile by running:
Alternatively, the package can be built from source as follows.
Clone the git repo:
Create a shell.nix file:
Note that the tests fail on NixOS, so disable them with —no-check . Also, haddock currently doesn’t work for stack, so —no-haddock disables it.
Install stack to your user profile:
For more information on using Stack together with Nix, please see the NixOS manual section on Stack.
Linux (generic)¶
Installer script¶
Manual download¶
Download the latest release:
Extract the archive and place stack somewhere on your $PATH (see Path section below)
Ensure you have required system dependencies installed. These include GCC, GNU make, xz, perl, libgmp, libffi, and zlib. We also recommend Git and GPG. To install these using your package manager:
- Debian / Ubuntu: sudo apt-get install g++ gcc libc6-dev libffi-dev libgmp-dev make xz-utils zlib1g-dev git gnupg netbase
- Fedora / CentOS: sudo dnf install perl make automake gcc gmp-devel libffi zlib zlib-devel xz tar git gnupg (use yum instead of dnf on CentOS and Fedora stack setup on a 32-bit system, you may need to run sudo dnf install ncurses-compat-libs . If this package is not installed, Stack may not be able to install 32-bit GHC versions. Also sudo dnf install ncurses-compat-libs if you nee
Arch Linux: sudo pacman -S make gcc ncurses git gnupg xz zlib gmp libffi zlib
- In order to use stack setup with older versions of GHC or on a 32-bit system, you may need the ncurses5-compat-libs AUR package installed. If this package is not installed, Stack may not be able to install older ( ncurses package with USE=tinfo (without it, stack will not be able to install GHC).
Now you can run stack from the terminal.
You can install stack by copying it anywhere on your PATH environment variable. A good place to install is the same directory where stack itself will install executables. On Windows, that directory is %APPDATA%\local\bin , e.g. c:\Users\Michael\AppData\Roaming\local\bin . For other systems, it’s $HOME/.local/bin .
If you don’t have that directory in your PATH, you may need to update your PATH (such as by editing
If you’re curious about the choice of these paths, see issue #153
Shell auto-completion¶
To get tab-completion of commands on bash, just run the following (or add it to .bashrc ):
For more information and other shells, see the shell auto-completion page
China-based users¶
If you’re attempting to install stack from within China:
As of 2020-02-24, the download link has limited connectivity from within mainland China. If this is the case, please proceed by manually downloading (ideally via a VPN) and installing stack per the instructions found on this page pertinent to your OS.
After install, your
/.stack/config.yaml will need to be configured before stack can download large files consistently from within China (without reliance on a VPN). Please add the following to the bottom of the
/.stack/config.yaml file (for Windows: use the %STACK_ROOT%\config.yaml):
Using an http proxy¶
To use stack behind a http proxy with ip address IP and port PORT, first set up an environment variable http_proxy and then run the stack command. e.g.
Note that on most operating systems, it is not mandatory for programs to follow the «system-wide» http proxy. Some programs, such as browsers, do honor this «system-wide» http proxy setting, while other programs, including bash, do not. That means configuring «http proxy setting» in your Control Panel (Windows) or System Preferences (Mac) would not result in stack traffic going through the proxy.
Upgrade¶
There are essentially four different approaches to upgrade:
The stack tool itself ships with an upgrade command, which download a stack binary or build it from source and install it to the default install path (e.g.
/.local/bin or %APPDATA%\local\bin ; see the Path section above). You can use stack upgrade to get the latest official release, and stack upgrade —git to install from Git and live on the bleeding edge. Make sure the default install directory is on your PATH and takes precedence over the system installed stack , or copy stack from that directory to the system location afterward. For more information, see this discussion.
If you’re using a package manager and are happy with sticking with the officially released binaries from the distribution (which may the lag behind latest version of Stack significantly), simply follow your normal package manager strategies for upgrading (e.g. apt-get update && apt-get upgrade ).
The get.haskellstack.org script supports the -f argument to over-write the current stack executable. For example:
curl -sSL https://get.haskellstack.org/ | sh -s — -f
- Manually follow the steps above to download the newest binaries from the release page and replace the old binary.
Install Older Versions¶
To install a specific version of stack, navigate to the desired version on the GitHub release page, and click the appropriate link under its «Assets» drop-down menu.
Alternatively, use the URL https://github.com/commercialhaskell/stack/releases/download/vVERSION/stack-VERSION-PLATFORM.EXTENSION . For example, the tarball for stack 2.1.0.1, osx-x86_64 is at https://github.com/commercialhaskell/stack/releases/download/v2.1.0.1/stack-2.1.0.1-osx-x86_64.tar.gz .
Here’s a snippet for appveyor.yml files, borrowed from dhall ‘s appveyor.yml . Change the values of PATH and VERSION as needed.
Copyright (c) 2015-2021, Stack contributors
Источник
Haskell
Haskell is a general-purpose, statically typed, purely functional programming language with type inference and lazy evaluation. Developed to be suitable for teaching, research and industrial application, Haskell has pioneered a number of advanced programming language features such as type classes, which enable type-safe operator overloading. Haskell’s main implementation is the Glasgow Haskell Compiler (GHC). It is named after logician Haskell Curry.
Contents
Installation
Haskell generates machine code that can be run natively on Linux. There is nothing special required to run a binary (already compiled) software, like xmonad or pandoc provided in the official repositories. On the other side, building AUR packages or developing software require a compiler and build tools to be installed.
To install the latest version of Haskell, install the following packages from the official repositories:
- ghc (GHC) — A Haskell compiler. There are several implementations available, but the one used most (which is now de facto the reference) is the GHC (Glasgow Haskell Compiler).
- cabal-install (Cabal) — A build tool focused on dependency resolution and sources packages from Hackage. Hackage is the Haskell community’s central package archive of open source software.
- stack (Stack) — A build tool focused on curated snapshots and sources packages from Stackage. Stackage is a stable subset of Hackage that provides curated sets (snapshots) of packages known to work well with each other. Alternatively, Stack can be installed through stack-staticAUR package. It provides statically linked binaries, thereby avoiding dozens of haskell-* dependencies.
You can install and configure either Cabal or Stack or both of them. Most of the popular Haskell packages support both Cabal and Stack.
Configuration
Since version 8.0.2-1, the Arch ghc package and all haskell-* packages in community provide only dynamically linked libraries. Therefore, to link successfully one must configure GHC, Cabal and Stack for dynamic linking, as the default is to use static linking.
Using dynamic linking typically results in faster builds and smaller disk and RAM usage (by sharing pages between multiple running Haskell programs), and will free you from troubleshooting cross-GHC mixing errors. But it has its own disadvantage: all tools you install from source will break on every update of ghc , ghc-libs or haskell-* packages since libraries compiled with GHC do not provide a stable ABI. When running such broken binary, you will see the usual message error while loading shared libraries: libHS. so: cannot open shared object file: No such file or directory . To fix this, just rebuild and reinstall the broken tool in order to relink it to newer libraries.
On the other hand, static linking is generally easier to maintain and does not force you to rebuild all tools from source after every update of their dependencies. For these reasons, static linking is often the preferred option for local development outside of the package system. If you prefer static linking, see #Static linking or #Alternate installations for details.
Invoking GHC directly
In order to link successfully one must pass the -dynamic flag to GHC. You can try it with the following file:
Compile and run it with:
Configuring Cabal for dynamic linking
First, run the following command to download the latest list of packages from Hackage and create global configuration file
/.cabal/config (or the file $CABAL_CONFIG points to):
To configure Cabal for dynamic linking, uncomment and edit the following options in
- library-vanilla: False suppresses the creation of static libraries (if your project contains a library).
- shared: True enables the creation of shared libraries (if your project contains a library).
- executable-dynamic: True causes dynamic linking to be used for executables (if your project contains executables).
- ghc-options: -dynamic adds the -dynamic flag to every invocation of GHC (e.g. if a package has a non-trivial Setup.hs ).
Configuring Stack for dynamic linking
You can use stack setup command to initialize Stack and create global configuration file
/.stack/config.yaml . By default Stack will automatically download its own version of GHC to an isolated location upon first invocation. To force Stack to use system GHC installation instead, run stack setup with —system-ghc and —resolver flags:
Note that you need to specify a resolver which is compatible with your system GHC. Otherwise Stack will happily ignore —system-ghc flag and download its own copy of GHC. You can determine the version of system GHC using ghc —version command:
Then visit Stackage website and pick a suitable Long Term Support (LTS) or nightly snapshot matching your system GHC version. Use the selected snapshot for —resolver flag on the command line, e.g. —resolver lts-16.15 or —resolver nightly-2020-09-01 .
Stackage typically lags behind new GHC releases. It may happen that no Stackage snapshot for your system GHC has yet been released. In this case you might want to choose a snapshot for some earlier minor version of GHC or temporarily downgrade your Haskell installation and wait until support for newer GHC releases finally lands on Stackage.
To configure Stack for dynamic linking, add the following snippet to
Package management
Most of Haskell libraries and executables are distributed in units of source packages available from Hackage and Stackage.
As is common in other compiled languages, a number of popular Haskell packages are available from official Arch repositories in pre-built form. Some additional packages can be installed from AUR.
Although it is recommended to use pacman to install GHC, libraries and tools from official repositories — at some point you may want to install Haskell packages directly from Hackage/Stackage or compile your own (or somebody else’s) packages from source. You will need Cabal or Stack for doing that.
The following table summarizes the advantages and disadvantages of different package management styles.
Method | Pros | Cons |
---|---|---|
Official repositories | Provided by Arch Linux developers, consistent versions of packages, already compiled | Not all packages available, only dynamic libraries available |
Cabal | All packages available, root not required | Installed in home directory, failures in dependency resolution, difficult to remove specific packages |
Stack | All packages available (favors Stackage), root not required | Installed in home directory, versions are pinned to snapshot, difficult to remove specific packages |
AUR | Additional packages available | Risk of unmaintained or orphaned packages, incompatible versions of packages possible |
Cabal
Cabal is «the original» build system for Haskell. Most of libraries and tools you can find on Hackage can be installed via Cabal.
Installing packages
To run user-wide executables installed by Cabal,
/.cabal/bin must be added to the $PATH environment variable. This can be done by putting the following line in your shell configuration file, for instance
Run the following command to install a Hackage package and all of its dependencies in a single step:
/.cabal/config while building packages with build-type: Custom . Therefore, it is necessary to specify —ghc-options=-dynamic flag on the command line otherwise you might experience build errors in setup.hs like Could not find module ‘Prelude’ There are files missing in the ‘base-. ’ package .
You can also build and install a Haskell package from source. To do this, run the following command from the package directory:
Each Cabal package should specify a list of its dependencies and their version constraints in the .cabal file according to the Package Versioning Policy (PVP). During the package installation, Cabal tries to find a set of dependencies that satisfies all the constraints. This process is called dependency resolution.
There are reasons why Stack exists; Cabal is known to generate a lot of friction with beginners. Most of the time dependency resolution works well but sometimes it fails. In this case you will need to figure out the cause of the problem and give Cabal some hints about how to resolve offending dependencies. For example, sometimes it is necessary to say cabal install —allow-newer —ghc-options=-dynamic package to allow Cabal to ignore package’s PVP-dictated upper bounds on dependency versions, effectively installing package with newer dependencies than the package author has permitted. It gets hairier for less-well maintained packages; for another example, see this thread about installing Idris (another programming language, written in Haskell), where one had to use both —allow-newer and —constraint=’haskeline command-line flags to get a successful compile.
Removing packages
There is no easy way to do it. Cabal does not have support for this functionality but there are external tools like cabal-store-gc.
To reinstall the entire user-wide Haskell package system, remove
/.ghc and start from scratch. This is often necessary when GHC is upgraded.
For more precision, it’s possible to use ghc-pkg unregister package or ghc-pkg hide package / ghc-pkg expose package directly on the user package database — this makes GHC «forget» about an installed package (or pretend it’s not there). However neither of these removes any files.
Stack
Stack is another tool to manage Haskell packages. It has slightly different goals than Cabal, with a slightly different philosophy. It uses Cabal library under the hood and integrates with Hackage — but maintains its own repositories of packages (snapshots) on Stackage with the promise that snapshots are curated and include packages which work well together.
Installing packages
In its default configuration, Stack installs compiled executables to
/.local/bin . Add this directory to the $PATH environment variable in your shell configuration file, for instance
Run the following command to download, build and install a Stackage package:
/.stack/config.yaml while building Setup.hs . If you experience build errors in Setup.hs like Could not find module ‘Prelude’ There are files missing in the ‘base-. ’ package , try to install ghc-static package as a workaround.
You can also build and install a Haskell package from source by running the following command from the package directory:
Note that you should specify the same resolver as one used for stack setup command.
Removing packages
Stack does not support the «uninstall» operation.
If you want to reinstall the entire user-wide Haskell package system, remove
/.stack directory and start from scratch. This is often necessary when GHC is upgraded.
Development tools
Tools
haskell-language-server
haskell-language-server is a Language Server Protocol (LSP) implementation for Haskell. It provides IDE-like features such as code completion, “goto definition”, documentation on hover, linting, formatting or refactoring for any editor integrating with the LSP.
If you are using dynamically linked Haskell packages from pacman, install haskell-language-server from the official repositories. Otherwise, if you prefer static linking, install haskell-language-server-static AUR . This package contains statically linked binaries for each supported version of GHC. Alternatively, haskell-language-server can be installed via ghcup or by the Haskell extension for Visual Studio Code.
haskell-language-server will attempt to automatically determine the build configuration when you open your project. If automatic detection fails, you might want to configure it manually using a hie.yaml file in the project root directory.
ghcid
ghcid is a GHCi-based tool for Haskell development that provides simple and robust way to display compiler errors and warnings on every source code change. It can be installed via ghcid AUR package.
hoogle
hoogle allows you to search the Haskell libraries by either function name, or by approximate type signature. It can be installed via hoogle package.
An online version of hoogle is available at https://hoogle.haskell.org.
Linters
hlint
hlint suggests possible improvements to Haskell code such as using alternative functions, simplifying code and spotting redundancies. It is available through hlint package.
stan is a Haskell static analyzer, complementary to hlint. It is in the beta phase as of June 2021.
weeder
weeder is an application to perform whole-program dead-code analysis.
Formatters
- brittany — Haskell source code formatter.
https://github.com/lspitzner/brittany || haskell-brittany
- Floskell — Fork of hindent focusing on flexibility and configurability.
https://github.com/ennocramer/floskell || haskell-floskell
- Fourmolu — Fork of Ormolu that adds an ability to configure various formatting parameters.
https://github.com/parsonsmatt/fourmolu || haskell-fourmolu
- hindent — Extensible Haskell pretty printer.
https://github.com/mihaimaruseac/hindent || hindent
- Ormolu — Formatter for Haskell source code, implementing one “true” formatting style which admits no configuration.
https://github.com/tweag/ormolu || haskell-ormolu
- stylish-haskell — Simple Haskell code prettifier.
https://github.com/jaspervdj/stylish-haskell || stylish-haskell
Editors
Visual Studio Code
Visual Studio Code has a Haskell extension powered by haskell-language-server. If you do not have haskell-language-server installed, the Haskell extension will automatically download and install statically linked Linux binaries for you.
IntelliJ IDEA
IntelliJ IDEA support for Haskell is provided by the Haskell plugin. It works with any edition of IntelliJ IDEA including intellij-idea-community-edition from the official repositories.
You will need to install Stack in order to create a new project or import an existing one into IntelliJ IDEA. As of June 2021 Cabal-only projects are not supported.
Basic syntax highlighting and indentation for Vim can be obtained via the haskell-vim plugin. For better IDE-like experience use one of LSP client plugins (e.g. coc.nvim, ALE, LanguageClient-neovim) together with haskell-language-server.
Emacs
Basic Emacs support for Haskell is provided by the official haskell-mode. For more advanced features, also use lsp-haskell with haskell-language-server.
Alternate installations
/.stack directories if they exist.
There are two officially recommended methods of installing Haskell on any generic Linux distribution: ghcup and Stack. Both methods install statically linked GHC, tools and libraries in your home directory.
The advantage of using ghcup or Stack instead of Haskell packages from the official repositories is the ability to install and manage multiple versions of GHC side by side. Cabal and Stack installed this way typically work right out of the box without any additional configuration, which might be easier for beginners.
A completely different way of installing Haskell is Nix package manager. Nix has a steeper learning curve but offers greater flexibility in managing both Haskell and non-Haskell packages in a reliable and reproducible fashion.
ghcup
ghcup is a command line tool that allows to easily install multiple versions of GHC and switch between them. It is similar in scope to rustup, pyenv and jenv.
Install ghcup-hs-bin AUR package. Alternatively, you may follow official installation instructions or manually download ghcup binary and place it somewhere into your $PATH .
By default, ghcup will install GHC executables into
/.ghcup/bin . You need to add this directory to the $PATH environment variable in your shell configuration file, for instance
/.zshrc for zsh . If you want to run executables installed by Cabal, add
/.cabal/bin to $PATH as well:
ghcup provides a convenient TUI which supports most of its functionality:
Alternatively, you can use the following CLI commands:
List available versions of GHC and Cabal:
Install the recommended version of GHC:
You can also install a specific version of GHC, for example:
The commands above do not automatically make GHC available on the $PATH . You need to select which GHC version to use by default:
Install the recommended version of Cabal:
You can now use Cabal to build and install statically linked Haskell executables without any special configuration or command line flags:
To start a new Cabal project:
To install haskell-language-server, use the following command:
For more information, refer to official ghcup and Cabal documentation.
Stack
Install stack-static AUR package. Alternatively, you may follow official installation instructions or manually download Stack binary and place it somewhere into your $PATH .
If you want to run executables installed by Stack, add
/.local/bin directory to the $PATH environment variable in your shell configuration file, for instance
Run stack setup to automatically install GHC from the latest Stackage LTS snapshot:
You can now use Stack to build and install statically linked Haskell packages without any special configuration or command line flags:
For more information, refer to official Stack documentation.
This article or section needs expansion.
Tips and tricks
Static linking
/.stack directories if they exist.
To use static linking, one must, at minimum, install the static boot libraries through the ghc-static package. This would allow you to build projects that depend exclusively on the boot libraries as well as on any other libraries that are not installed through the haskell-* packages from the official repositories.
Unfortunately, if your project depends on any of dynamically linked haskell-* packages that you have installed, Cabal does not take the absence of static libraries into account during dependency resolution. As a result, it will try to use the existing haskell-* package and then fail with linker errors when it discovers the static libraries are missing:
Unlike ghc-static , there are no “ haskell-*-static ” packages available for linkage. There are other ways to work around this issue though, as described in each of the sections below.
Static global package database
A direct approach is offered by the official ghc-static package, which exposes an alternative «static» global package database at /usr/lib/ghc-version/static-package.conf.d . The static database is limited to only the statically linkable boot packages, therefore if Cabal is reconfigured to use the static database instead of the default database, it would behave as though the dynamic-only haskell-* packages do not exist.
The precise path of the static database could be determined at build time using a command such as:
Here is how to enable the static database for use:
- When building packages with Cabal, one can pass the following flag to limit the selection of global packages to only the boot packages:
- When building directly using GHC rather than Cabal, one can pass the following flags to override the global package database:
ghc-pristine
Install ghc-pristine AUR package, which wraps over an existing GHC installation to create a separate GHC distribution in /usr/share/ghc-pristine , with a package database that contains only boot libraries. This effectively creates a semi-isolated environment without dynamically linked haskell-* packages, but still makes use of the GHC compiler from the official repositories. Then, to build software with static linking, one simply needs to invoke the wrapped compiler /usr/share/ghc-pristine/bin/ghc . For Cabal, this amounts to the following configuration in
You can also specify the path to the compiler on a per-project basis by running the following command from the project directory:
cabal-static
Another way to gain back static linking on Arch is to install cabal-static AUR package. Unlike the official cabal-install , this one does not pull dynamically linked haskell-* dependencies from the official repositories and avoids mixing static and shared Haskell libraries installed on the same system. Then you can use Cabal as usual with the following limitation: you have to make sure that the only other Haskell packages you have installed are ghc , ghc-libs and ghc-static (not cabal-install , stack and none of the haskell-* packages available in the official repositories).
stack-static
Install stack-static AUR package. Similarly to cabal-static method, make sure that the only other Haskell packages you have installed from the official repositories are ghc , ghc-libs and ghc-static . Then setup Stack to use system GHC as explained in #Configuring Stack for dynamic linking:
To make these options permanent, paste the following snippet to
This configuration will allow you to build statically linked packages as you would normally do, but using system GHC installation instead of GHC provided by Stack.
hpack-static-bin
hpack-static-bin AUR provides a statically linked (meaning no haskell-* dependencies) alternative to haskell-hpack . It is precompiled, so no make dependencies are needed.
ghcup
ghcup is a tool that can install GHC locally, entirely outside the system package manager. Additionally, it supports multiple versions of GHC side by side. Using the GHC provided by this tool will completely avoid the difficulties associated with static linking since the system GHC is not used at all. It also naturally avoids breakages in locally built libraries caused by upgrades of the system GHC and its boot libraries.
Источник