bookkeeper: Anonymous records and overloaded labels

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

Please see README.md for more information and examples.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.1.1.0, 0.1.2.0, 0.2.0.0, 0.2.1.0, 0.2.1.1, 0.2.2.0, 0.2.3, 0.2.4, 0.2.5
Change log CHANGELOG.md
Dependencies base (>=4.9 && <4.11), bookkeeper, data-default-class, markdown-unlit, type-level-sets [details]
Tested with ghc ==8.0.1, ghc ==8.2.1
License BSD-3-Clause
Copyright (c) Julian K. Arni
Author Julian K. Arni
Maintainer jkarni@gmail.com
Category Data Structures, Records
Home page http://github.com/turingjump/bookkeeper#readme
Bug tracker https://github.com/turingjump/bookkeeper/issues
Source repo head: git clone https://github.com/turingjump/bookkeeper
Uploaded by aminb at 2017-12-17T21:35:04Z
Distributions
Reverse Dependencies 1 direct, 1 indirect [details]
Executables readme
Downloads 7073 total (22 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 bookkeeper-0.2.5

[back to package description]

Bookkeeper Build Status

Bookkeeper is a new Haskell library that uses the new OverloadedLabels feature of GHC 8 to provide a new take on datatypes and records:

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE OverloadedLabels #-}
import Bookkeeper


jane :: Book '[ "name" :=> String, "age" :=> Int ]
jane = emptyBook
     & #name =: "Jane"
     & #age =: 30

-- >>> jane
-- Book {age = 30, name = "Jane"}
-- >>> jane ?: #name
-- "Jane"

It bears some similarities to Nikita Volkov's record library, but requires no Template Haskell.

Accesing a field that does not exist is a type error, made nicer with GHCs new custom type errors:

 -- >>> jane ?: #address
--   • The provided Book does not contain the field "address"
--     Book type:
--     '["age" ':-> Int, "name" ':-> String]

The order in which fields are inserted or appear in types does not matter. That is, in:

-- type A = Book '[ "field1" :=> Int,  "field2" :=> Bool]
-- type B = Book '[ "field2" :=> Bool, "field1" :=> Int ]

Types A and B are the same.

You can set, modify, or get fields. See the haddocks for more information.

main :: IO ()
main = return ()