The labels package

[ Tags: bsd3, development, library ] [ Propose Tags ]

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, 0.3.3
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
Category Development
Home page https://github.com/chrisdone/labels#readme
Source repository head: git clone https://github.com/chrisdone/labels
Uploaded Tue Aug 29 09:02:04 UTC 2017 by ChrisDone
Distributions LTSHaskell:0.3.3, NixOS:0.3.3, Stackage:0.3.3, Tumbleweed:0.3.2
Downloads 354 total (26 in the last 30 days)
Rating 0.0 (0 ratings) [clear rating]
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-08-29 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for labels-0.3.3

[back to package description]

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>