polytropos-optics: optics-core integration for polytropos open records and variants

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

Integration between polytropos and the optics / optics-core ecosystem.

Provides Van Laarhoven lenses for record fields via Polytropos.Optics.fieldLens, first-class prisms for variant constructors via Polytropos.Optics.ctorOptic, and Optics.Label.LabelOptic instances allowing #fieldName lens syntax with OverloadedLabels.

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


[Skip to Readme]

Modules

  • Polytropos
    • Polytropos.Optics

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), optics-core (>=0.4 && <0.5), polytropos-core (>=0.1 && <0.2) [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:24Z
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-optics)
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-optics-0.1.0.2

[back to package description]

polytropos-optics

Profunctor optics integration for polytropos open records and variants via optics-core.

Overview

polytropos-optics provides profunctor-based optics compatible with the optics ecosystem, offering improved type error messages and faster compile times compared to traditional Van Laarhoven lenses.

Features

  • fieldLens: Lens' for record fields with clean optics composition (%~, .~, ^.).
  • ctorOptic: Prism' for variant constructors.
  • LabelOptic: Enables #fieldName syntax with OverloadedLabels.

Quick Example

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

import Optics.Core
import Polytropos
import Polytropos.Optics

type Person = Record '["name" ':= String, "age" ':= Int]

alice :: Person
alice = REC { name = "Alice", age = 30 }

-- Read via overloaded label:
aliceAge :: Int
aliceAge = alice ^. #age

-- Update via overloaded label:
olderAlice :: Person
olderAlice = alice & #age %~ (+ 1)

-- Variant prism traversal:
type Shape = Variant '["Circle" ':= '["radius" ':= Double]]

myCircle :: Shape
myCircle = VAR { Circle = REC { radius = 5.0 } }

circleRadius :: Maybe Double
circleRadius = preview (ctorOptic (Field @"Circle") % #radius) myCircle

License

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