labels

Anonymous records via named tuples https://github.com/chrisdone/labels#readme

Version on this page:0.3.0
LTS Haskell 9.20:0.3.3
Stackage Nightly 2017-12-16:0.3.3
Latest on Hackage:0.3.3
BSD3 licensed by Chris Done
Maintained by chrisdone@gmail.com

Module documentation for 0.3.0

labels

Declare and access tuple fields with labels

This package is experimental, exploring the design space opened up by the implemented and to-be-implemented work on extensible records in GHC.

Note: You need GHC 8.0.1.

Basic examples

The haddock docs are here.

Enable these extensions:

  • In GHCi: :set -XOverloadedLabels -XTypeOperators -XDataKinds -XFlexibleContexts

  • In a module: {-# LANGUAGE OverloadedLabels, TypeOperators, DataKinds, FlexibleContexts #-}

Let's use GHCi:

> import Labels
> :set -XOverloadedLabels -XTypeOperators -XDataKinds -XFlexibleContexts
Construct a record
> (#foo := "hi", #bar := 123)
(#foo := "hi",#bar := 123)
Get fields of a record
> get #bar (#foo := "hi", #bar := 123)
123
Set fields of a record
> set #bar 66 (#foo := "hi", #bar := 123)
(#foo := "hi",#bar := 66)
Modify fields of a record
> modify #mu (*0.1) (#bar := "hi", #mu := 123)
(#bar := "hi",#mu := 12.3)
Add fields to a record
> cons (#mu := [1,2,3]) (#foo := "hi", #bar := 123)
(#mu := [1,2,3],#foo := "hi",#bar := 123)
Abstraction
> let double field record = set field (get field record * 2) record
> double #mu (#bar := "hi", #mu := 123)
(#bar := "hi",#mu := 246)

Changes

0.3.1:
* Export Labels class.

0.3.1:
* Add Subset class.

0.3.0:
* Put labels in its own class.
* Change type of labels to take a Proxy.

0.2.0:
* Add "reflect" and "labels" functions.
* Drop support for GHC <8.

0.1.2:
* Add docs for "project" function.

0.1.1:
* Add "project" function.

0.1.0:
* Drop the convenience accessor #foo. Must use get #foo

0.0.0:
* First version
Depends on 2 packages:
Used by 1 package:
comments powered byDisqus