fields
First-class record field combinators with infix record field syntax.
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
tuples.
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
"Data.Record.Field".
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
packages?
* 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
levels.
* 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
issue.
| version | uploaded | uploader | changes | |
|---|---|---|---|---|
| 0.1.0 | 2010-08-11 11:15 UTC | JussiKnuuttila | +1189/−0 lines, 9 filesdep +arraydep +basedep +containerssetup-changed |
Dependencies of fields-0.1.0
array >=0.3.0.0 0.5.7.0 → 0.5.8.0
| 2024-09-08 07:13 UTC | 0.5.8.0 | +204/−8 lines, 6 filesdep ~basePVP ok |
| 2024-04-12 14:38 UTC | 0.5.7.0 | +34/−17 lines, 9 filesdep ~basePVP: major bump suggested |
| 2023-07-10 15:24 UTC | 0.5.6.0 | +159/−39 lines, 8 filesdep ~basenew-uploaderPVP ok |
| 2023-02-13 16:01 UTC | 0.5.5.0 | +8/−4 lines, 3 filesdep ~basenew-uploaderPVP ok |
| 2019-09-01 06:48 UTC | 0.5.4.0 | +33/−8 lines, 5 filesdep ~basesetup-changedPVP: major bump suggested |
showing 5 of 18 versions
base >=4 && <5 4.22.0.0 → 4.22.1.0
| 2026-12-01 12:38 UTC | 4.22.1.0 | +388/−6 lines, 9 filesdep ~ghc-internalPVP: major bump suggested |
| 2025-12-19 11:52 UTC | 4.22.0.0 | +886/−215 lines, 28 filesdep ~ghc-internalPVP ok |
| 2026-03-27 12:26 UTC | 4.21.2.0 | +10/−3 lines, 4 filesdep ~ghc-internalPVP ok |
| 2025-12-27 10:31 UTC | 4.21.1.0 | +17/−5 lines, 4 filesdep ~ghc-internalPVP ok |
| 2024-12-16 09:24 UTC | 4.21.0.0 | +1170/−396 lines, 39 filesdep ~ghc-internalPVP ok |
showing 5 of 61 versions
containers >=0.3.0.0 0.8 → 0.8.1
| 2026-10-04 06:08 UTC | 0.8.1 | +8085/−5169 lines, 39 filesdep +template-haskell-liftdep ~arraydep ~deepseqPVP: major bump suggested |
| 2025-03-01 13:03 UTC | 0.8 | +8447/−7031 lines, 37 filesnew-uploaderPVP ok |
| 2023-09-27 12:15 UTC | 0.7 | +76/−33 lines, 3 filesPVP ok |
| 2023-09-28 04:21 UTC | 0.6.8 | +644/−184 lines, 17 filesdep ~basedep ~deepseqPVP: major bump suggested |
| 2023-02-01 03:11 UTC | 0.6.7 | +783/−229 lines, 20 filesPVP: major bump suggested |
showing 5 of 43 versions
fclabels >=0.9.1 2.0.5 → 2.0.5.1
| 2021-05-27 18:41 UTC | 2.0.5.1 | +69/−23 lines, 3 filesdep ~basedep ~base-orphansdep ~criterionPVP ok |
| 2020-05-22 09:42 UTC | 2.0.5 | +19/−12 lines, 3 filesdep ~basedep ~template-haskellPVP ok |
| 2020-01-28 20:23 UTC | 2.0.4 | +19/−32 lines, 3 filesdep +base-orphansPVP: major bump suggested |
| 2018-02-13 06:09 UTC | 2.0.3.3 | +12/−7 lines, 2 filesdep ~basedep ~criteriondep ~mtlPVP: major bump suggested |
| 2016-11-24 13:23 UTC | 2.0.3.2 | +7/−5 lines, 2 filesdep ~HUnitdep ~basedep ~criterionPVP ok |
showing 5 of 55 versions
monads-fd >=0.1.0.1 0.1.0.4 → 0.2.0.0
| 2010-11-07 15:08 UTC | 0.2.0.0 | +15/−560 lines, 7 filesdep +mtldep ~basePVP ok |
| 2010-11-07 15:10 UTC | 0.1.0.4 | +560/−15 lines, 7 filesdep −mtldep ~basePVP: major bump suggested |
| 2010-11-02 21:20 UTC | 0.1.0.3 | +19/−562 lines, 7 filesdep +mtldep ~basePVP: major bump suggested |
| 2010-09-10 22:10 UTC | 0.1.0.2 | +45/−44 lines, 22 filesdep ~transformersPVP: major bump suggested |
| 2010-05-03 00:26 UTC | 0.1.0.1 | +25/−6 lines, 5 filesPVP: minor bump suggested |
showing 5 of 8 versions
transformers >=0.2.0.0 0.6.2.0 → 0.6.3.0
| 2026-01-12 12:42 UTC | 0.6.3.0 | +28/−1 lines, 4 filesPVP: major bump suggested |
| 2025-04-06 22:39 UTC | 0.6.2.0 | +41/−42 lines, 8 filesdep ~ghc-primPVP: major bump suggested |
| 2024-09-25 11:37 UTC | 0.6.1.2 | +70/−21 lines, 19 filesPVP: minor bump suggested |
| 2023-08-01 19:13 UTC | 0.6.1.1 | +281/−42 lines, 11 filesPVP ok |
| 2023-02-04 08:15 UTC | 0.6.1.0 | +64/−4 lines, 8 filesPVP ok |
showing 5 of 42 versions
Reverse dependencies
1 packages depend on fields