polytropos-profunctors: Pure profunctor optics for polytropos open records and variants

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

Integration between polytropos and the profunctors ecosystem.

Provides pure profunctor lenses and prisms (Polytropos.Profunctors.Lens, Polytropos.Profunctors.Prism) operating directly over Polytropos's unboxed Data.Primitive.SmallArray.SmallArray memory layout: * Polytropos.Profunctors.fieldLens for record fields via compile-time Polytropos.Core.FieldIndex. * Polytropos.Profunctors.ctorPrism for variant constructors via Polytropos.Core.ConstructorIndex. * Zero-overhead Polytropos.Profunctors.slotLens and Polytropos.Profunctors.variantPrism indexed by array slots and constructor tags.

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


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.2
Change log CHANGELOG.md
Dependencies base (>=4.14 && <5), polytropos-core (>=0.1 && <0.2), primitive (>=0.7 && <1), profunctors (>=5.6 && <6), tagged (>=0.8 && <1) [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:40Z
Category Optics, Data, Control
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-profunctors)
Distributions
Downloads 4 total (4 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for polytropos-profunctors-0.1.0.2

[back to package description]

polytropos-profunctors

Pure profunctor optics integration for polytropos open records and variants via profunctors.

Overview

polytropos-profunctors provides first-class profunctor lenses and prisms (Lens, Prism, view, preview, review, over, set) operating directly over Polytropos's unboxed SmallArray memory layout.

Unlike polytropos-optics (which relies on optics-core) or polytropos-lens (which depends on Edward Kmett's lens), polytropos-profunctors requires only the lightweight profunctors package (Data.Profunctor.Strong, Data.Profunctor.Choice), making it ideal for categorical frameworks, arrow engines (such as Kernmantle), and streaming pipelines.

Features

  • fieldLens: High-level typed profunctor lens focusing on an open record field via compile-time FieldIndex.
  • ctorPrism: High-level typed profunctor prism focusing on an open variant constructor via compile-time ConstructorIndex.
  • slotLens & typedSlotLens: Low-level profunctor lenses focusing on physical array slots with dual-mode in-place updates.
  • variantPrism & typedVariantPrism: Low-level profunctor prisms matching unboxed constructor tags in \(O(1)\) time.

Quick Example

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

import Polytropos
import Polytropos.Profunctors

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

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

-- Read field via profunctor lens:
aliceAge :: Int
aliceAge = view (fieldLens (Field @"age")) alice  -- 30

-- Update field via profunctor lens:
olderAlice :: Person
olderAlice = over (fieldLens (Field @"age")) (+ 1) alice  -- age = 31

-- Variant constructor matching:
type Shape = Variant '["Circle" ':= '["radius" ':= Double]]

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

circlePayload :: Maybe (Record '["radius" ':= Double])
circlePayload = preview (ctorPrism (Field @"Circle")) myCircle

License

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