Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable in Cabal (Haskell)

Tags:

haskell

cabal

I am trying to write a package in Haskell. This package contains a library and an executable. I am specifying this in the Cabal file. There are three basic components of the library:

1) There are the exposed modules of the library

2) There are internal build-dependencies that should not be exported as part of the library

3) There are external build-dependencies.

There is a bit of overlap in the Cabal file. For the library I write:

exposed-modules: The List of Exposed Modules

other-modules: The List of other modules

build-depends: The List of build dependencies

Then for the executable other-modules: The list of exposed modules and other modules are needed in the executable build-depends: The list of build dependencies

What would be nice is if Cabal lets me have a variable.

V1 = List exposed modules

V2 = List other modules

V3 = List build dependencies

Then in the executable, for example, I could do

other-modules: V1,V2

build-depends: V3

Alternatively, I would take a recommendation for a better way to use the Cabal system!

like image 424
Jonathan Gallagher Avatar asked Oct 22 '22 01:10

Jonathan Gallagher


1 Answers

No, this is not possible yet. I think we have a feature request for something like this on the issue tracker somewhere. Note, however, that your executable can depend on the library defined in the same .cabal file, so you don't have to share exposed-modules and other-modules:

Name: some-package
Version: 0.1
[...]

Library
    build-depends: some-dependency >= 1.0, ...        
    exposed-modules: A, B, C
    other-modules: C, D, E
    [...]

Executable some-exe
    main-is: SomeExe.hs
    build-depends: some-package == 0.1

For a real-world example, see here.

like image 195
Mikhail Glushenkov Avatar answered Oct 23 '22 15:10

Mikhail Glushenkov