Minimal Cabal Files, revisited

Daniel Díaz Carrete
2 min readFeb 14, 2020

Back in 2017, Juan Pedro Villa Isaza wrote an interesting post called Minimal Cabal Files. How time flies! We are now in 2020 and cabal-install has reached version 3.0. What has changed in the field of Cabal minimalism?

Let’s take a look:

cabal-version: 3.0
name: foo
version: 1.0.0.0
executable foo
main-is: Main.hs
build-depends: base, foo
default-language: Haskell2010
library
exposed-modules: Foo
build-depends: base
default-language: Haskell2010

Notice that cabal-versionis now at the beginning of the file, and has an exact version instead of a version bound like >= 1.10. This is explained in the documentation:

Starting with cabal-version: 2.2 this field is only valid if fully contained in the very first line of a package description […] For package descriptions using a format prior to cabal-version: 1.12 the legacy syntax resembling a version range syntax cabal-version: >= 1.10 needs to be used. […] This legacy syntax is supported up until cabal-version: >= 2.0 it is however strongly recommended to avoid using the legacy syntax. See also #4899.

Notice as well that we didn’t have to specify build-type: Simple. This is because

When cabal-version is set to 2.2 or higher, the default is Simple unless a custom-setup exists, in which case the inferred default is Custom.

Even in such small Cabal file, there’s some repetition. Both the library and the executable have a dependency onbase, also both specify default-language: Haskell2010. How about we factor those bits using a common stanza? Like this:

cabal-version: 3.0
name: foo
version: 1.0.0.0
common dry
build-depends: base
default-language: Haskell2010
executable foo
import: dry
main-is: Main.hs
build-depends: foo
library
import: dry
exposed-modules: Foo
build-depends: base

--

--