MyNixOS website logo
Description

Unpacked containers via backpack.

This backpack mixin package supplies unpacked sets and maps exploiting backpack's ability to unpack through signatures.

unpacked-containers

This package supplies a simple unpacked version of Data.Set and Data.Map using backpack.

This can remove a level of indirection on the heap and unpack your keys directly into nodes of your sets and maps.

The exported modules roughly follow the API of containers 0.5.11, but with all deprecated functions removed.

Note however, that all CPP has been removed relative to containers, because on one hand, use of backpack locks us to a current version of GHC, and on the other there is a bug in GHC 8.2.2 that prevents the use of CPP in a module that uses backpack. This issue is resolved in GHC 8.4.1, so as that comes into wider usage if we need to track containers API changes going forward and those need CPP we can just drop support for 8.2.2.

It is intended that you will remap the names of the modules. from Set.* or Map.* to some portion of the namespace that is peculiar to your project, and so the module names are designed to be as short as possible, mirroring the usage of containers but with the Data prefix stripped off.

Usage

To work this into an existing haskell project, you'll need to be on GHC >= 8.2.2, and use cabal >= 2.

First build an internal library for your project that has a module that matches the Key signature.

module MyKey where

type Key = ()

You can put whatever you want in for Key as long as it is an instance of Ord.

Then in your cabal file you can set up your internal library as an extra named internal library (multiple library support was added in cabal 2).

library my-keys
  exposed-modules: MyKey
  build-depends: base

and in your library or executable that wants to work with sets or maps of that key type use

library
  build-depends: unpacked-containers, my-keys
  mixins: unpacked-containers (Set as MyKey.Set) requires (Key as MyKey)

If you need several Sets or Maps you can use several mixins: clauses.

If you need to expose the set type, remember you can use a reexported-modules: stanza.

Now you work with MyKey.Set as a monomorphic set type specific to the type of Key you specified earlier.

See the executable unpacked-set-example and library example sections in the unpacked-containers.cabal file for a minimal working example.

Documentation

To build haddocks for this project you need to run cabal new-haddock as cabal-haddock doesn't work.

Contact Information

Contributions and bug reports are welcome!

Please feel free to contact me through github or on the #haskell IRC channel on irc.freenode.net.

-Edward Kmett.

Metadata

Version

0

Executables (1)

  • bin/unpacked-set-example

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows