I just recently started learning Haskell and its tooling.
Stack seems to be the way to go, and today is the first time I try to add a dependency to my project!
It is nothing else than “regex-prce2” because I want to use PRCE2 regex on my project
So I’ve added:
But when I execute stack build I get the following error:
Error: [S-4804]
Stack failed to construct a build plan.
While constructing the build plan, Stack encountered
the following errors. The 'Stack configuration' refers
to the set of package versions specified by the
snapshot (after any dropped packages, or pruned GHC
boot packages; if a boot package is replaced, Stack
prunes all other such packages that depend on it) and
any extra-deps:
In the dependencies for aoc2024-0.1.0.0:
* regex-prce2 must match >=1.0, but no version is in
the Stack configuration (no matching package and
version found. Perhaps there is an error in the
specification of a package's dependencies or
build-tools (Hpack) or build-depends, build-tools
or build-tool-depends (Cabal file) or an omission
from the packages list in
Documents/Projects/Personal/haskell/aoc2024/stack.yaml
(project-level configuration).)
The above is/are needed since aoc2024 is a build
target.
This is very haunting, can someone give me a hint of whats going on? I assume that stack can’t find the package… but its published in Hackage, so I don’t get whats wrong
For more context, this is the stack snapshot I use:
Stack does not use Hackage directly. Instead it uses Stackage snapshots, which are lists of packages with fixed versions that are known to work well together. The regex-pcre2 package is unfortunately not in the snapshot that you are using. You can tell stack to use external packages by adding this in your stack.yaml file:
Side question… can you recommend me a good Regex library just for matching simple regex?
I am just learning haskell by solving advent of code and I just need a simple regex for a simple match
This might be a good learning opportunity. Haskell’s String are lists of characters, and so there’s a lot of matching logic that you can write as lists. For example, if you want to match strings where the first character is 'a', and the third character is either '1' or '5', you can write:
I also could not get regex-pcre2-1.0.0.0 (for PCRE2) to work.
In respect of the earlier version of PCRE, on Windows, I use this package.yaml for a toy single-package test project:
name: regex-pcre-test
version: 0.1.0.0
dependencies:
- base >= 4.7 && < 5
- regex-pcre # Specify my package has this dependency ...
library:
source-dirs: src
and this project-level configuration file (stack.yaml):
snapshot: lts-23.14 # GHC 9.8.4, and includes a regex-pcre version
stack build fails with a message about a missing C library:
regex-pcre > Configuring regex-pcre-0.95.0.1...
regex-pcre > Error: Cabal-simple_O_vy6YIf_3.10.3.0_ghc-9.8.4.exe: The pkg-config package
regex-pcre > 'libpcre' is required but it could not be found.
Searching, I find that a MSYS2 package can supply that C library and so I add it to the Stack-supplied MSYS2 with:
stack exec -- pacman -S mingw-w64-x86_64-pcre
Now, stack build works as expected (extract only):
regex-pcre > configure
regex-pcre > Configuring regex-pcre-0.95.0.1...
regex-pcre > build with ghc-9.8.4
...
regex-pcre > Registering library for regex-pcre-0.95.0.1..
regex-pcre-test> configure (lib)
...
Registering library for regex-pcre-test-0.1.0.0..
Completed 2 action(s).
On Ubuntu (via WSL 2), a similar experience except obtaining the C library is done by:
Alright so basically you have to install the missing C libraries into your system yourself
Not great but if it works it works
I ended up using regex-tdfa, and although I was not familiar with POSIX-like regex style I ended up learning enough to solve my problem
It was easier since regex-tdfa is fully built in Haskell so no C is required and it is already in the Stack snapshot apparently
There are solutions for Haskell projects that involve a mix of dependencies on Haskell libraries and C libraries.
In particular, on Linux and macOS only, there is a package manager known as Nix. Stack can be configured to integrate with Nix, such that Nix handles the non-Haskell dependencies and Stack handles the Haskell dependencies (as usual). For futher information see: Nix integration - The Haskell Tool Stack and https://nixos.org/.
However, I don’t have much direct experience, as I am a Windows user. For my part, I mainly use the MSYS2 project to add C libraries to the Stack-supplied MSYS2.
I subsequently managed to get regex-pcre2-1.0.0.0 to compile on Windows. This is what I did:
First, Stack’s error message was:
regex-pcre2 > error: Wrap.hsc:369:84: error: use of undeclared identifier 'PCRE2_ALT_EXTENDED_CLASS'
regex-pcre2 > hsc_enum (CompOption, CompOption, hsc_printf ("%s", "compAltExtendedClass "), PCRE2_ALT_EXTENDED_CLASS);
I noted that the change log for the PCRE2 project says that PCRE2_ALT_EXTENDED_CLASS was introduced in version 10.45. I double-checked the MSYS2 version of the C library that I had: it was only 10.44.