cabal icon indicating copy to clipboard operation
cabal copied to clipboard

common blocks or implicit common stanzas

Open daig opened this issue 6 years ago • 5 comments

It would be nice to be able to avoid writing the same imports everywhere - this becomes relevant as backpack encourages many internal libraries with similar cabal properties.

The most general way I can imagine is common import blocks that would look something like

import: my-common
   library lib-a
        ...
    library lib-b
        ...
    test-suite test-a
        ...

where each piece within the indented scope implicitly imports my-common.

another possibility with even less boilerplate at the cost of being less general is to have toplevel implicit imports like

library-common
    build-depends: base
    ...

so that all libraries import it. There'd also be similar constructs for executable, test-suite, benchmark, foreign-library, etc.

daig avatar Aug 18 '18 16:08 daig

Have you seen the original design discussion at #2832 ? The idea of implicit common blocks was anticipated there already

hvr avatar Aug 18 '18 17:08 hvr

afaik cabal already supports common stanzas, which can include common dependencies, so this could be closed?

jneira avatar Jun 12 '21 17:06 jneira

#2832 is closed so I think we can close this @daig thanks for your original feature request

jneira avatar Jun 12 '21 17:06 jneira

afaik cabal already supports common stanzas, which can include common dependencies, so this could be closed?

this issue is different, it's about a common stanzas enhancement that would reduce import bolerplate

and it looks like the proposed extension in #2832:

  • reserve a few special common stanza ids all, library, test-suites, and benchmark to declare common stanzas that are implicitly included by the respective named real stanza. In the example above we could have used common all instead of common cdef1 and all include cdef1 simply removed.

wasn't implemented, nor was the proposed unnamed stanza.

I'm not sure why is that. @phadej @hvr was there a reason for it?

fgaz avatar Jun 13 '21 14:06 fgaz

Oh sorry, i missed the implicit part.

jneira avatar Jun 13 '21 17:06 jneira