overloaded-records-0.1.0.0: Overloaded Records based on current GHC proposal.

Copyright(c) 2016, Peter Trško
LicenseBSD3
Maintainerpeter.trsko@gmail.com
Stabilityexperimental
PortabilityCPP, DeriveDataTypeable, DeriveGeneric, LambdaCase, NoImplicitPrelude, RecordWildCards, TemplateHaskell, TupleSections
Safe HaskellNone
LanguageHaskell2010

Data.OverloadedRecords.TH

Contents

Description

Derive magic instances for OverloadedRecordFields.

Synopsis

Derive OverloadedRecordFields instances

overloadedRecords Source

Arguments

:: DeriveOverloadedRecordsParams

Parameters for customization of deriving process. Use def to get default behaviour.

-> Name

Name of the type for which magic instances should be derived.

-> DecsQ 

Derive magic OverloadedRecordFields instances for specified type name.

type MakeAccessorName = String -> String -> Word -> Maybe String -> Maybe String Source

Pseudo type definition:

:: TypeName
-> ConstructorName
-> FieldIndex
-> Maybe AccessorName
-> Maybe OverloadedLabelName

If field has an accessor then the function will get its name or Nothing otherwise. Function has to return Nothing in case when generating overloaded record field instances is not desired.

FieldIndex is starting from zero.

makeAccessorName :: Functor f => (MakeAccessorName -> f MakeAccessorName) -> DeriveOverloadedRecordsParams -> f DeriveOverloadedRecordsParams Source

Lens for accessing function that specifies what magic instances will be defined and what will be the names of overloaded record fields.

defaultMakeAccessorName Source

Arguments

:: String

Name of the type, of which this field is part of.

-> String

Name of the constructor, of which this field is part of.

-> Word

Field position as an argument of the constructor it is part of.

-> Maybe String

Name of the field (record) accessor; Nothing means that there is no record accessor defined for it.

-> Maybe String

Overloaded label name for the field; Nothing means that there shouldn't be a label associated with it.

Suppose we have a weird type definition as this:

data SomeType = SomeConstructor
    { _fieldX :: a
    , someTypeFieldY :: b
    , someConstructorFieldZ :: c
    }

Then for each of those fields, defaultMakeAccessorName will produce expected OverloadedLabel name:

  • _fieldX --> fieldX
  • someTypeFieldY --> fieldY
  • someConstructorFieldZ --> fieldZ

Any other field name is kept unchanged.