polytropos-core: Row-polymorphic / open ADTs: rows, generic representation, evidence

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

Core engine and consumer surface of polytropos: row-polymorphic extensible records and variants for Haskell.

The package collapses the four quadrants of the design space (nominal products, structural products, nominal sums, and structural sums) into one uniform generic representation (Polytropos.Core.Rep): a runtime integer tag plus a contiguous, flat Data.Primitive.SmallArray.SmallArray of payload slots.

For application development and daily usage, start at the front door module Polytropos, which exposes ergonomic constructors, pattern synonyms, and worked examples. For compiler plugins and low-level substrate primitives, see Polytropos.Core.

For design decisions, memory physics, and background on the OCaml polymorphic variant heritage, see POLYTROPOS_DESIGN.md.


[Skip to Readme]

Modules

  • Polytropos
    • Polytropos.Core

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.18 && <4.23), primitive (>=0.9 && <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:22Z
Category 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-core)
Distributions
Reverse Dependencies 18 direct, 0 indirect [details]
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-core-0.1.0.2

[back to package description]

polytropos-core

Row-polymorphic / open algebraic data types (ADTs) and high-performance matching generics for Haskell.

polytropos-core collapses the four quadrants of nominal vs. structural products and sums into a single generic runtime representation (Rep: an unpacked tag plus a flat SmallArray of payload slots). Moving between nominal and structural data becomes an erased choice at the type level rather than an impedance mismatch at runtime.

Key Features

  • Unified Flat Representation: A single representation for records and variants (Rep) backed by contiguous primitive arrays.
  • \(O(1)\) Field Access and Update: Literal slot indexing without runtime inductive dictionary walks or pointer chasing.
  • Pattern Matching & Hybrid Eliminators: Zero-overhead variant elimination (eliminateUniform, eliminateUniformM, eliminate, peel) executing through unrolled jump tables.
  • Higher-Kinded Data (HKD): Native support for functor-wrapped records (RecordF f r) and variants (VariantF f r).
  • Ergonomic Front Door: Re-exports convenient record syntax, pattern synonyms, and lens-friendly helpers in Polytropos.

Quick Example

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

import Polytropos

type UserRow = '[ "id" := Int, "name" := String, "active" := Bool ]
type User = Record UserRow

-- 1. Construction without ($) grouping:
alice :: User
alice = REC { id = 42, name = "Alice", active = True }

-- 2. Direct field access via record dot syntax:
userId :: Int
userId = alice.id

-- 3. Functional record update without parentheses:
alicePromoted :: User
alicePromoted = REC_UPD alice { active = False }

-- 4. Passing record expressions without ($):
describeUser :: User -> String
describeUser u = u.name ++ " (ID: " ++ show u.id ++ ")"

summary :: String
summary = describeUser REC { id = 101, name = "Bob", active = True }

Documentation & Repository

License

Dual-licensed under the European Union Public Licence v1.2 (EUPL-1.2) OR the Apache License, Version 2.0 (Apache-2.0).