The labels package

[Tags:bsd3, library]

Declare and access tuple fields with labels. An approach to anonymous records.


[Skip to Readme]

Properties

Versions 0.0.0, 0.1.0, 0.1.1, 0.1.2, 0.2.0, 0.3.0, 0.3.1, 0.3.2
Change log CHANGELOG
Dependencies base (>=4.9.0.0 && <5), template-haskell [details]
License BSD3
Copyright 2016 Chris Done
Author Chris Done
Maintainer chrisdone@gmail.com
Stability Experimental
Category Development
Home page https://github.com/chrisdone/labels#readme
Source repository head: git clone https://github.com/chrisdone/labels
Uploaded Sat Feb 18 12:59:04 UTC 2017 by ChrisDone
Distributions LTSHaskell:0.3.2, NixOS:0.3.2, Stackage:0.3.2, Tumbleweed:0.3.2
Downloads 153 total (17 in the last 30 days)
Votes
0 []
Status Docs available [build log]
Last success reported on 2017-02-18 [all 1 reports]

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for labels

Readme for labels-0.3.2

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
<table> <tr><td>Construct a record</td><td><pre lang="haskell"> > (#foo := "hi", #bar := 123) (#foo := "hi",#bar := 123) </pre></td></tr> <tr><td>Get fields of a record</td><td><pre lang="haskell"> > get #bar (#foo := "hi", #bar := 123) 123 </pre></td></tr> <tr><td>Set fields of a record</td><td><pre lang="haskell"> > set #bar 66 (#foo := "hi", #bar := 123) (#foo := "hi",#bar := 66) </pre></td></tr> <tr><td>Modify fields of a record</td><td><pre lang="haskell"> > modify #mu (*0.1) (#bar := "hi", #mu := 123) (#bar := "hi",#mu := 12.3) </pre></td></tr> <tr><td>Add fields to a record</td><td><pre lang="haskell"> > cons (#mu := [1,2,3]) (#foo := "hi", #bar := 123) (#mu := [1,2,3],#foo := "hi",#bar := 123) </pre></td></tr> <tr><td>Abstraction</td><td><pre lang="haskell"> > let double field record = set field (get field record * 2) record > double #mu (#bar := "hi", #mu := 123) (#bar := "hi",#mu := 246) </pre></td></tr> </table>