How to create a simple project using Cabal?

The Haskell wiki says you should use Cabal as your build system. However, it seems to me much more focused on creating packages, and then just creating binary files. Basically, all I want to do is build each * .hs file in my src / directory into a separate binary in bin /. This makefile does a great job of this, but I want to learn about Cabal and it seems like a good example to get me started:

GHC = ghc GHCFLAGS = -outputdir bin SRC = $(wildcard src/*.hs) BIN = $(patsubst src/%.hs,%,$(SRC)) all: $(addprefix bin/, $(BIN)) bin/%: src/%.hs $(GHC) $(GHCFLAGS) $< -o $@ clean: rm bin/* 
+6
source share
1 answer

The easiest way to get started is to get Cabal to generate a .cabal file for you, which you can use as a starting point. To do this, go to the project directory and enter

 $ cabal init 

He will then ask you a bunch of questions about your package. Some questions, such as the author’s name and email address, really matter if you plan to upload your package to Hackage so you can leave them blank if you want. After that, you can edit the .cabal file to configure it. The generated file will contain a bunch of comments that should help you get started. After that just enter

 $ cabal configure $ cabal build 

By default, the binary will be placed in ./dist/build/<name>/ .

+8
source

Source: https://habr.com/ru/post/908552/


All Articles