The overloaded-records package

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain]

Implementation of Overloaded Record Fields based on current GHC proposal. It is built on top of functionality that is included in GHC 8.0.1, but it works on older GHC versions as well. Most importantly, this library provides Template Haskell functions for automatic deriving of instancess for HasField and SetField type classes. With these instances overloaded fields can be used directly as getters and lenses.

See README for usage examples.

This implementation is highly experimental and may change rapidly.

More about the current status of OverloadedRecordFields language extension can be found on: GHC Wiki: OverloadedRecordFields.


[Skip to ReadMe]

Properties

Versions0.1.0.0, 0.2.0.0, 0.2.0.0, 0.3.0.0, 0.4.0.0, 0.4.1.0, 0.4.2.0
Change logChangeLog.md
Dependenciesbase (>=4.7 && <5), data-default-class (==0.0.*), template-haskell (>=2.9 && <2.12) [details]
LicenseBSD3
Copyright(c) 2016, Peter Trško
AuthorPeter Trško
Maintainerpeter.trsko@gmail.com
CategoryData
Home pagehttps://github.com/trskop/overloaded-records
Bug trackerhttps://github.com/trskop/overloaded-records/issues
Source repositoryhead: git clone git://github.com/trskop/overloaded-records.git
this: git clone git://github.com/trskop/overloaded-records.git(tag 0.2.0.0)
UploadedTue Mar 1 20:45:40 UTC 2016 by PeterTrsko

Modules

[Index]

Flags

NameDescriptionDefaultType
pedantic

Pass additional warning flags to GHC.

DisabledManual

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainers' corner

For package maintainers and hackage trustees


Readme for overloaded-records-0.2.0.0

[back to package description]

Overloaded Records

Hackage Hackage Dependencies Haskell Programming Language BSD3 License

Build

Description

Implementation of Overloaded Record Fields based on current GHC proposal. It is built on top of functionality that is included in GHC 8.0.1, but it works on older GHC versions as well. Most importantly, this library provides Template Haskell functions for automatic deriving of instancess for HasField and SetField type classes. With these instances overloaded fields can be used directly as getters and lenses.

import Data.OverloadedRecords.TH (overloadedRecord)

newtype Bar a = Bar {_bar :: a}

overloadedRecord def ''Bar

On GHC 8.0.1 it is possible to just write:

{-# LANGUAGE OverloadedLabels #-}

import Control.Lens ((+~))

add :: Int -> Bar Int -> Bar Int
add n = #bar +~ n

For older GHC versions there is a family of Template Haskell functions that will derive overloaded labels in form of standard haskell definitions:

import Control.Lens ((+~))
import Data.OverloadedLabels.TH (label)

label "bar"

add :: Int -> Bar Int -> Bar Int
add n = bar +~ n

This implementation is highly experimental and may change rapidly.

More about the current status of OverloadedRecordFields language extension can be found on GHC Wiki: OverloadedRecordFields.

Usage Example

{-# LANGUAGE DataKinds #-}              -- overloadedRecord, labels
{-# LANGUAGE FlexibleContexts #-}       -- labels
{-# LANGUAGE FlexibleInstances #-}      -- overloadedRecord
{-# LANGUAGE MultiParamTypeClasses #-}  -- overloadedRecord
{-# LANGUAGE TemplateHaskell #-}        -- overloadedRecord, labels
{-# LANGUAGE TypeFamilies #-}           -- overloadedRecord
module FooBar
  where

import Data.Default.Class (Default(def))

import Data.OverloadedRecords.TH (overloadedRecord)
import Data.OverloadedLabels.TH (label, labels)


data Foo a = Foo
    { _x :: Int
    , _y :: a
    }

overloadedRecord def ''Foo
labels ["x", "y"]

newtype Bar a = Bar {_bar :: a}

overloadedRecord def ''Bar
label "bar"

License

The BSD 3-Clause License, see LICENSE file for details. This implementation is based on original prototype, which is under MIT License.

Contributions

Contributions, pull requests and bug reports are welcome! Please don't be afraid to contact author using GitHub or by e-mail.