Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: 954864ab33
Fetching contributors…

Cannot retrieve contributors at this time

162 lines (142 sloc) 7.564 kB
-- fields.cabal auto-generated by cabal init. For additional options,
-- see
-- The name of the package.
Name: fields
-- The package version. See the Haskell package versioning policy
-- ( for
-- standards guiding when and how versions should be incremented.
Version: 0.1.1
-- A short (one-line) description of the package.
Synopsis: First-class record field combinators with infix
record field syntax.
-- A longer description of the package.
Description: Using records, especially nested records, in
Haskell can sometimes be a bit of a chore.
Fortunately, there are several libraries in hackage
that make working with records easier. This library
is my attempt to build on top of these libraries to
make working with records even more pleasant!
In most imperative languages, records are accessed
using the infix dot operator. Record fields can be
read simply by suffixing a record value with
'.field' and they can be modified by simply
assigning to that location. Although this is not
the only way to access records (indeed, Haskell
does not use it), many people (including myself)
like it. This library attempts to support this
style for Haskell records in the following manner:
> record.field.subfield becomes record .# field # subfield
> record.field = value becomes record .# field =: value
Of course, the infix assignment in Haskell is pure
and doesn't actually mutate anything. Rather, a
modified version of the record is returned.
In addition, the following features are supported:
* Accessing several fields simultaneously using
Example: @record .# (field1, field2, field3)@
* Accessing records inside a @'Functor'@.
Example: @recordInFunctor \<.#\> field@
* Composing fields with @'Applicative'@ functors
and @'Monad'@s.
Example: @record .\# applicativeField \<\#\> subfield@
* Pattern matching using @ViewPatterns@.
Example: @case record of (match field -> 1) -> ...@
* Easy comparisons etc. using @'onField'@.
Example: @sortBy (compare \`onField\`
field#subfield) records@
For a detailed description of usage, see
This library is a work-in-progress. Some
limitations, deficiencies, points of interest and
possible future improvements include:
* Currently, a @'Field'@ instance is only provided
for @"fclabels"@ lenses, since that is what I
have personally used. However, there should be
nothing in principle that would prevent adding
instances for @"data-accessor"@ and @"lenses"@.
However, doing this would make this package
depend on several record libraries at once,
which might not be the best approach. Perhaps
this package should be split into several
* Similarly, the @'field'@ method currently
returns an @"fclabels"@ lens. To fully decouple
this package from @"fclabels"@, the @'field'@
method probably has to be split into @getField@,
@setField@ and @modField@ or something similar.
* For monad transformers, @"transformers"@ and
@"monads-fd"@ are used, since those are what
@"fclabels"@ uses. This might be a problem for a
program that uses @"mtl"@ instead.
* To avoid lots of parentheses, @"fields"@ uses
high-precedence operators at three operator
precedence levels. The goal was to make field
accesses directly usable in arithmetic
expressions (e.g. @r1\.\#int + r2\.\#int@).
Unfortunately, since Haskell has a finite number
of precedence levels, this goal was not properly
met, since @('*')@ and all higher-precedence
arithmetic operators have conflicting precedence
* Performance has not been analyzed at all. To my
knowledge, GHC doesn't do type class
specialization or method inlining by default, so
needlessly generic code might be generated, even
if all types are statically known. I'm hoping
that this can be addressed using @SPECIALIZE@
and @INLINE@ pragmas if it turns out to be an
-- The license under which the package is released.
License: BSD3
-- The file containing the license text.
License-file: LICENSE
-- The package author(s).
Author: Jussi Knuuttila
-- An email address to which users can send suggestions, bug reports,
-- and patches.
-- A copyright notice.
-- Copyright:
Category: Data
Build-type: Simple
-- Extra files to be distributed with the package, such as examples or
-- a README.
Extra-source-files: Example.hs
-- Constraint on the version of Cabal needed to build this package.
Cabal-version: >=
-- Modules exported by the library.
Exposed-modules: Data.Record.Field
, Data.Record.Field.Basic
, Data.Record.Field.Combinators
, Data.Record.Field.Tuple
, Data.Record.Field.Indexable
-- Packages needed in order to build this package.
Build-depends: base >= 4 && < 5
, fclabels >= 0.9.1
, containers >=
, array >=
, transformers >=
, monads-fd >=
-- Modules not exported by this package.
-- Other-modules:
-- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.
-- Build-tools:
Jump to Line
Something went wrong with that request. Please try again.