polytropos-generics: Structural datatype generics, representation bridging, and whole-data traversal

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

Generic deriving, representation bridging, and structural traversal engine for polytropos.

This package bridges nominal Haskell algebraic data types (ADTs) to and from the unified flat representation Polytropos.Core.Rep, and provides zero-overhead structural operations (Polytropos.Generics.geq, Polytropos.Generics.gcompare, Polytropos.Generics.gshowsPrec, Polytropos.Generics.gmap, Polytropos.Generics.gfoldMap) across open rows (Polytropos.Record, Polytropos.Variant) and nominal types.

Unlike large-generics (which is strictly record-only and models 1D SOP products), polytropos-generics unifies sums and products into one tagged representation backed by a 2D dictionary matrix (SmallArray (SmallArray (DictAny c))) for O(1) constructor dispatch. Unlike standard GHC.Generics, it executes as tight unrolled loops over flat contiguous memory rather than traversing nested binary trees.

Start at the front door module Polytropos.Generics for architectural rationales, usage guidance, and worked examples for both open rows and nominal ADTs.


[Skip to Readme]

Modules

  • Polytropos
    • Polytropos.Generics

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), polytropos-core (>=0.1 && <0.2), primitive (>=0.7 && <0.10) [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:23Z
Category Generics, 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-generics)
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-generics-0.1.0.2

[back to package description]

polytropos-generics

Generic deriving, representation bridging, and structural traversal engine for polytropos.

Overview

polytropos-generics connects GHC's native GHC.Generics mechanism with open rows, enabling frictionless conversion between standard nominal data types and open Record / Variant values.

Features

  • FromGeneric & ToGeneric: Zero-overhead translation between nominal Haskell ADTs and flat Rep structures.
  • Structural Row Conversions: Cast between nominal types sharing identical field shapes without manual mapping code.
  • DerivingVia Ergonomics: Derive typeclasses for nominal types via their structural row representation.

Quick Example

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

import GHC.Generics (Generic)
import Polytropos
import Polytropos.Generics

data Person = Person { name :: String, age :: Int }
  deriving (Show, Eq, Generic)

-- Convert nominal ADT to open structural record:
toRow :: Person -> Record '[ "name" := String, "age" := Int ]
toRow = fromGeneric

-- Convert open structural record back to nominal ADT:
fromRow :: Record '[ "name" := String, "age" := Int ] -> Person
fromRow = toGeneric

License

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