I'm pretty new to working with Haskell. My professor is having us use it for class.
Currently working on Mac. While going through some tutorials, I found out I had to download the regex package for some of them to work. I've tried downloading the package through cabal, but I keep getting an error when it tries to build:
clang: error: linker command failed with exit code 1
I haven't been able to find any working solutions to this problem, as the ones that I have found have relied on installing the Haskell platform, which seems to be practically defunct as of last year (the page linking to it literally tells me to go away and use GHC).
I did attempt to redownload cabal following these instructions, but when I try to install regex I get the same error.
I am very much at a loss.
Welcome!
Either Homebrew or ghcup should be fine for your purposes. By “downloading the package through cabal” I infer that you tried
cabal install regex. Unfortunately, this likely isn’t what you need—it’s meant for using Cabal to build and install a program, not for installing a library for a program to use.You can run a single-file program by specifying its dependencies in a header at the top of the file, and using
cabal run.If this is saved in
Example.hs, then you should be able to run it withcabal run Example.hs.The more common workflow for using a package is to make a project with
cabal init.Then you can add a dependency in the
build-dependssection of the Cabal file, in this caseexample.cabal. Here you can writeregexby itself or include a version constraint such asregex >= 1.1.0.2(the latest as I write this). Then you should be able to build your project withcabal buildand run it withcabal exec.