polytropos-dhall: High-performance Dhall codecs and generic adapters for polytropos open rows

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

Linear O(N) Dhall.Marshal.Decode.FromDhall and Dhall.Marshal.Encode.ToDhall codecs and generic adapters for polytropos open records and variants via dhall.

Unlike GHC.Generics which builds deeply nested binary tree nodes ((:*:), (:+:)) during serialization, polytropos-dhall unrolls the flat contiguous Data.Primitive.SmallArray.SmallArray payload directly into Dhall record and union literals and back. Variants serialize into Dhall union expressions with O(1) constructor tag dispatch.

Also provides generic adapters via Dhall.Marshal.Decode.GenericFromDhall and Dhall.Marshal.Encode.GenericToDhall (Polytropos.Dhall.GenericDhall) enabling seamless DerivingVia integration for nominal Haskell types and gachi substrates.

Start at the front door module Polytropos.Dhall for complete documentation, codec options, and worked examples.


[Skip to Readme]

Modules

[Index] [Quick Jump]

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), bytestring (>=0.10 && <0.13), dhall (>=1.42 && <1.43), either (>=5.0 && <5.1), polytropos-core (>=0.1 && <0.2), polytropos-plugin (>=0.1 && <0.2), primitive (>=0.7 && <0.10), text (>=1.2 && <2.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:40Z
Category Data, Configuration
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-dhall)
Distributions
Downloads 4 total (4 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-10-21 [all 1 reports]

Readme for polytropos-dhall-0.1.0.2

[back to package description]

polytropos-dhall

High-performance Dhall configuration language codecs and generic adapters for polytropos open records and variants.

Overview

Unlike GHC.Generics which constructs intermediate binary tree representations ((:*:), (:+:)) during serialization, polytropos-dhall unrolls the flat contiguous SmallArray payload directly into Dhall record and union AST expressions and back.

In addition to first-class open row codecs, polytropos-dhall provides generic adapters around Dhall.Marshal.Decode.GenericFromDhall and Dhall.Marshal.Encode.GenericToDhall, enabling turnkey DerivingVia configuration decoding for nominal types and downstream substrates such as gachi.

Features

  • Heterogeneous Record Codecs: Automatic ToDhall and FromDhall instances for open records (Record r) via compile-time field dictionary unrolling.
  • Tagged Variant Codecs: High-performance constructor dispatch encoding variants into Dhall union expressions (< Foo : { ... } | Bar : { ... } >).
  • Higher-Kinded Record Codecs: Turnkey support for RecordF f r (such as RecordF Maybe r with automatic Nothing defaults on omitted fields).
  • Generic Adapters: Turnkey GenericDhall adapter for deriving (FromDhall, ToDhall) via (GenericDhall MyType) over GHC Generic.
  • Homogeneous Fast Path: Introspection and reflection helpers for uniform records and sum rows.

Quick Example

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

import Dhall (input, auto, embed, inject)
import qualified Data.Text.IO as TIO
import Polytropos
import Polytropos.Dhall

type ServerConfig = Record '["host" ':= Text, "port" ':= Natural, "active" ':= Bool]

main :: IO ()
main = do
  -- Construct open record using idiomatic REC syntax:
  let cfg = REC { host = "localhost", port = 8080, active = True } :: ServerConfig

  -- Encode directly to Dhall expression:
  let expr = embed inject cfg
  print expr

  -- Decode back from Dhall text:
  cfg' <- input auto "{ host = \"0.0.0.0\", port = 9000, active = False }"
  print (cfg' :: ServerConfig)

License

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