-
Notifications
You must be signed in to change notification settings - Fork 3
/
package.cabal
74 lines (67 loc) · 2.57 KB
/
package.cabal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
cabal-version: 3.0
name: lesson9-template-haskell
version: 1.0.0.0
build-type: Simple
-- https://vrom911.github.io/blog/common-stanzas
-- https://cabal.readthedocs.io/en/3.4/cabal-package.html#pkg-field-build-depends
common common
build-depends:
base >= 4 && < 5,
template-haskell
default-language: Haskell2010
ghc-options: -O2
library core
import: common
exposed-modules: Core
Core.TH
signatures: Core.SomeSig
hs-source-dirs: lib-core
library intermediate
import: common
-- This is an indefinite package, but notice that the module signature this
-- library inherits from "core" is not listed *explicitly*! But nevertheless
-- it's carried over: clients of "intermediate1" will be able to rename
-- the module signature in a mixin line for "intermediate1".
--
-- What if we want to *rename* the module signature inherited from core?
-- Then we need to add a mixin for core here.
exposed-modules: Intermediate
hs-source-dirs: lib-intermediate
build-depends: core,
intermediate-th
-- If we wanted to rename the sig inherited from core.
-- mixins:
-- core requires (Core.SomeSig as Intermediate1.SomeSig)
library intermediate-th
import: common
exposed-modules: Intermediate.TH
hs-source-dirs: lib-intermediate-th
-- this executable depends on the "intermediate1" package, but because
-- "intermediate" is indefinite, it must also provide an implementation for its
-- unfilled signatures.
--
-- Notice that the cabal file for "intermediate" doesn't explicitly export the module
-- signature, it's implicitly inherited from "core".
executable lesson9
import: common,
main-is:
Main.hs
build-depends:
intermediate,
lib-impl
-- This mixins section is only required because I intentionally made the name of
-- the module sig and the name of the implementation module different.
-- If they were the same, the matching would happen automatically.
mixins:
lib-impl (Core.SomeImpl as Core.SomeSig)
-- This internal library exists only to provide an implementation module for
-- the signature "intermediate2" inherits from "intermediate1".
--
-- Note that it doesn't know *anything* about either "intermediate2", "intemediate1" or "core"!
--
-- The implementation module can't be in the executable, because a compilation
-- unit can't fill a signature with a "local" module.
library lib-impl
import: common,
exposed-modules: Core.SomeImpl
hs-source-dirs: lib-impl