packed-data

[ bsd3, data, library, program ] [ Propose Tags ] [ Report a vulnerability ]

Build, traverse and deserialise packed data in Haskell


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.1.0.1
Dependencies base (>=4.7 && <5), bytestring (>=0.11.0.0 && <0.13), bytestring-strict-builder (>=0.4.5 && <0.5), deepseq (>=1.4.6.1 && <1.6), extra (>=1.0 && <2.0), mtl (>=2.2.2 && <2.4), packed-data, template-haskell (>=2.18.0.0 && <=2.24.0.0), time [details]
Tested with ghc ==9.2.8, ghc ==9.4.8, ghc ==9.6.6, ghc ==9.8.4, ghc ==9.10.1, ghc ==9.12.1
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-22T14:54:45Z
Distributions
Executables packed-exe
Downloads 21 total (21 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for packed-data-0.1.0.1

[back to package description]

packed-data for Haskell

Hackage Version Doc

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-data allows using packed data type-safely, without explicit pointer arithmetic.

A portable library

Unlike other implementations of packed-data-support (e.g. Gibbon), packed-data 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-data can be used with any version of GHC (as of today, it has been tested GHC 9.2-9.12).

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.

Documentation is available on Hackage

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.