This is the launch page for Backpack, actively maintained by Edward (as of Apr 2017).
Backpack is a proposal for retrofitting Haskell with an applicative, mix-in module system. It has been implemented in GHC 8.2.
The documentation for how to use Backpack is a bit scattered about at this point, but here are useful, up-to-date (as of 2017-04-02, prior to GHC 8.2's release) references:
- This pair of blog posts: Try Backpack, ghc --backpack and Cabal packages have up-to-date tutorials for using the main features of Backpack, with and without Cabal.
- The GHC manual section on module signatures gives the gory details about how Backpack's signature files (hsig) work. A more user-friendly version of this can be found on Haskell wiki "Module signature"
- There is not yet a manual entry in Cabal for how Cabal works. This section is under development.
- Edward Z. Yang's thesis contains detailed information about the specification and implementation of Backpack. We also have an older paper draft which was submitted to ICFP'16.
- Hackage does not yet support uploads of Backpack-using packages. next.hackage is a Hackage instances running a development branch of Hackage that can handle Backpack; for now, Backpack-enabled packages should be uploaded here.
Some more out-of-date documents:
- Backpack specification. This was subsumed by my thesis but once Backpack stabilizes it will be worth distilling the thesis PDF back into a more web-friendly format.
Make sure cabal-version is recent enough. (#4448) If you set the
cabal-version of your package too low, you may get this error:
Error: Mix-in refers to non-existent package 'pkg' (did you forget to add the package to build-depends?) In the stanza 'executable myexe' In the inplace package 'pkg'
This is because internal libraries are feature-gated by the
cabal-version of your package. Setting it to
cabal-version: >= 2.0 is enough to resolve the problem.
You can't instantiate a dependency with a locally defined module. Consider the following package:
library other-modules: StrImpl build-depends: foo-indef mixins: foo-indef requires (Str as StrImpl)
This looks like it should work, but actually it will fail:
Error: Non-library component has unfilled requirements: StrImpl In the stanza 'library' In the inplace package 'mypkg-1.2'
The reason for this is Backpack does not (currently) support instantiating a package with a locally defined module: since the module can turn around and *import* the mixed in
foo-indef, which would result in mutual recursion (not presently supported.)
To solve this problem, just create a new library to define the implementing module. This library can be in the same package using the convenience library mechanism:
library str-impl exposed-modules: StrImpl library build-depends: str-impl, foo-indef mixins: foo-indef requires (Str as StrImpl)
Backpack-related tickets are marked with keyword 'backpack'. If the ticket is assigned to ezyang, it means he's planning on working on it.