polytropos-lens: Comprehensive lens-suite integration for polytropos open records and variants

[ data, library, optics ] [ Propose Tags ] [ Report a vulnerability ]

Comprehensive optics integration between polytropos open records and variants and Edward Kmett's lens ecosystem.

Bridges the unified flat runtime representation Polytropos.Core.Rep to standard Control.Lens typeclasses: positional lenses (Control.Lens.Tuple.Field1 through Control.Lens.Tuple.Field9), label-based lenses (Polytropos.Lens.fieldLens), container indexing (Control.Lens.At.Ixed and Control.Lens.At.At keyed by field name), single-pass homogeneous traversals (Control.Lens.Each.Each), and first-class profunctor prisms (Polytropos.Lens.prismVariant) for open variant constructors with O(1) tag dispatch.

Keeps the core polytropos packages lightweight and free from transitive dependencies.

Start at the front door module Polytropos.Lens for complete documentation, usage guidelines, and worked examples.


[Skip to Readme]

Modules

  • Polytropos
    • Polytropos.Lens

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.2
Change log CHANGELOG.md
Dependencies base (>=4.14 && <5), lens (>=5.2 && <5.4), polytropos-core (>=0.1 && <0.2), polytropos-plugin (>=0.1 && <0.2), profunctors (>=5.6 && <5.7) [details]
License (EUPL-1.2 OR Apache-2.0)
Author Nadia Yvette Chambers
Maintainer nadia.yvette.chambers@ik.me
Uploaded by nyc at 2026-10-21T21:34:25Z
Category Optics, Data
Home page https://github.com/NadiaYvette/polytropos
Bug tracker https://github.com/NadiaYvette/polytropos/issues
Source repo head: git clone https://github.com/NadiaYvette/polytropos(packages/polytropos-lens)
Distributions
Downloads 3 total (3 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs pending
Build status unknown [no reports yet]

Readme for polytropos-lens-0.1.0.2

[back to package description]

polytropos-lens

Comprehensive Control.Lens optics integration for polytropos open records and variants.

Overview

polytropos-lens provides standard Van Laarhoven lenses for record fields and first-class prisms for variant constructors.

Features

  • fieldLens: \(O(1)\) Van Laarhoven lens for accessing and updating record fields:
    fieldLens @"name" :: Lens' (Record r) String
    
  • ctorPrism: \(O(1)\) constructor prism for variant injection and matching:
    ctorPrism @"Success" :: Prism' (Variant s) a
    
  • OverloadedLabels: Native #fieldName lens syntax via LabelOptic integration.

Quick Example

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedLabels #-}
{-# OPTIONS_GHC -fplugin=Polytropos.Plugin #-}

import Control.Lens
import Polytropos
import Polytropos.Lens

type Account = Record '[ "id" := Int, "balance" := Double ]

main :: IO ()
main = do
  let acc = REC { id = 101, balance = 500.0 }
  -- Access and update with standard lens operators:
  let acc' = acc & fieldLens @"balance" +~ 50.0
  print (acc' ^. fieldLens @"balance")

License

Dual-licensed under EUPL-1.2 OR Apache-2.0.