packages feed

polytropos-optics-0.1.0.4 / README.md

# polytropos-opticsProfunctor optics integration for [polytropos](https://github.com/NadiaYvette/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```haskell{-# LANGUAGE DataKinds #-}{-# LANGUAGE OverloadedLabels #-}{-# LANGUAGE TypeApplications #-}{-# OPTIONS_GHC -fplugin=Polytropos.Plugin #-}import Optics.Coreimport Polytroposimport Polytropos.Opticstype Person = Record '["name" ':= String, "age" ':= Int]alice :: Personalice = REC { name = "Alice", age = 30 }-- Read via overloaded label:aliceAge :: IntaliceAge = alice ^. #age-- Update via overloaded label:olderAlice :: PersonolderAlice = alice & #age %~ (+ 1)-- Variant prism traversal:type Shape = Variant '["Circle" ':= '["radius" ':= Double]]myCircle :: ShapemyCircle = VAR { Circle = REC { radius = 5.0 } }circleRadius :: Maybe DoublecircleRadius = preview (ctorOptic (Field @"Circle") % #radius) myCircle```## LicenseDual-licensed under `EUPL-1.2 OR Apache-2.0`.