packed-data

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Warnings:

Build, traverse and deserialise packed data in Haskell


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.0.0, 0.1.0.1
Change log None available
Dependencies base (>=4.7 && <5), bytestring (>=0.12.1.0 && <0.13), bytestring-strict-builder (>=0.4.5 && <0.5), deepseq (>=1.5.0.0 && <1.6), extra (>=1.0 && <2.0), mtl (>=2.3.1 && <2.4), packed-data, template-haskell (>=2.22.0.0 && <2.23), time (>=1.14 && <1.15) [details]
License BSD-3-Clause
Copyright 2025 Arthi-chaud
Author Arthi-chaud
Maintainer aj530@kent.ac.uk
Category Data
Home page https://github.com/Arthi-chaud/packed-haskell#readme
Bug tracker https://github.com/Arthi-chaud/packed-haskell/issues
Source repo head: git clone https://github.com/Arthi-chaud/packed-haskell
Uploaded by ArthiChaud at 2025-01-19T11:21:07Z

Modules

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for packed-data-0.1.0.0

[back to package description]

Packed Haskell

Build, traverse and deserialise packed data in Haskell.

What is this for?

When components of a system exchange data, each component has to make sure that they send data in a way the recipient will be able to read. A simple example is an API, sending JSON data for the client to parse. This process of decoding the data takes time, especially for big objects like HTML pages.

Packed data is data serialised into a binary format that is usable as-is, meaning there is no need to parse it to be able to use it. Another perk of such format is that it can be stored in files easily.

packed allows using packed data type-safely, without explicit pointer arithmetic.

A portable library

Unlike other implementations of packed-data-support (e.g. Gibbon), packed is a library that does not modify the compiler in any way. It relies solely on already existing libraries (like ByteString), Template Haskell and common GHC extensions. This means that, virtually, packed can be used with any version of GHC (although, as of today, it has only been tested with GHC 9.10).

Its API is inspired by an example from the Linear Haskell paper (code available here).

Example


import qualified Data.Packed.Reader as R
import Data.Packed

data Tree a = Leaf a | Node (Tree a) (Tree a)

$(mkPacked ''Tree '[])

-- Compute sum of values in the tree
sumPacked :: PackedReader '[Tree Int] r Int
sumPacked =
    caseTree -- Generated by Template Haskell
        ( R.do -- If Tree is a Leaf
            !n <- reader
            R.return n
        )
        ( R.do -- If Tree is a Node
            !left <- sumPacked
            !right <- sumPacked
            let !res = left + right
            R.return res
        )

getSum :: Packed '[Tree Int] -> IO Int
getSum = runReader sumPacked

packTree :: Tree Int -> Packed '[Tree Int] 
packTree = pack 

Take a look at the benchmark directory for more examples.

Benchmark

To run benchmarks, run the following command:

stack bench
# Saves the report as CSV
stack bench --ba --csv bench.csv
# Saves the report, and runs a specific test
stach bench --ba '--csv bench.csv sums'

Note: Graphs of the benchmark results will be generated in the graph/ directory when saving the report as CSV.