gongju: Pure type-level utility functions, arity composition, and curried combinators

[ combinators, functional, library, types ] [ Propose Tags ] [ Report a vulnerability ]

Gongju (공구 工具, toolsimplement) provides inductive Peano type-level utility functions in pure Haskell, replacing Template Haskell arity splices (e.g. composition-extra) and finite tuple generics (e.g. tuple-sop) with zero-overhead typeclass induction, bidirectional functional dependencies, and TypeApplications-friendly GHC.TypeLits.Nat wrappers.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log CHANGELOG.md
Dependencies adjunctions (>=4.4 && <5), base (>=4.20 && <5), comonad (>=5 && <6), contravariant (>=1.5 && <2), distributive (>=0.6 && <1), indexed (>=0.1 && <1), indexed-profunctors (>=0.1 && <1), kan-extensions (>=5.2 && <6), profunctors (>=5.6 && <6) [details]
Tested with ghc ==9.10.3, ghc ==9.12.4, ghc ==9.14.1
License (EUPL-1.2 OR Apache-2.0)
Author Nadia Yvette Chambers
Maintainer nadia.yvette.chambers@ik.me
Uploaded by nyc at 2026-11-03T19:38:34Z
Category Types, Functional, Combinators
Home page https://github.com/NadiaYvette/gongju
Bug tracker https://github.com/NadiaYvette/gongju/issues
Source repo head: git clone https://github.com/NadiaYvette/gongju.git(packages/gongju)
Distributions
Downloads 3 total (3 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 gongju-0.1.0.0

[back to package description]

gongju

Pure type-level utility functions, arity composition, and positional combinators for Haskell.

gongju (공구 / 工具, tools/implement) replaces Template Haskell arity generation (like composition-extra) and tuple generics (like tuple-sop) with pure type-level Peano induction, bidirectional functional dependencies, and type-safe argument permutations.


Key Modules

  • Gongju.Core — Re-exports all core modules and the Grand Unified Open-World Tape Engine (withOps, (.@)).
  • Gongju.Peano — Type-level Peano numbers ('Z, 'S), compile-time natural conversion (ToPeano, FromPeano), and reflection typeclasses.
  • Gongju.Composition — Variadic function composition (compN @n, ComposeN) and nested functor mapping (fmapN @n, FmapN) with bidirectional functional dependencies.
  • Gongju.Positional — In-place curried arrow combinators without heap allocation:
    • slipr @n (Yank): Pull the \(n\)-th argument to position 0.
    • slipl @n (Shove): Push argument 0 deeper to position \(n\).
    • twist @n (Twist): Swap adjacent arguments at depth \(n\) and \(n + 1\).
  • Gongju.Permute — Arbitrary argument permutation (permute @'[2, 0, 1], Permute) with full disambiguation of duplicate argument types.
  • Gongju.Indexed — Indexed monads, indexed applicatives, and indexed comonads (IxFunctor, IxApplicative, IxMonad, IxComonad).
  • Gongju.Comonad — Integrations with comonad and distributive (W, PullDist, Representable).
  • Gongju.Adjunction — Categorical adjunctions and dual pairing annihilation (zapLR, zapRL, AdjU, AdjC).
  • Gongju.Kan — Kan extensions, Yoneda and Coyoneda \(O(1)\) fusion, and Codensity CPS monad optimization (Ran, Lan, Yoneda, Codensity).
  • Gongju.Profunctor — Profunctor mapping grids (dimap), Curried category arrow permutation (CurriedCat, yankCat, permuteCat), right-nested tuple spine arrow permutations (yankTuple, permuteTuple), and profunctor strand input/output reordering (permuteInputs, permuteOutputs, permuteHandler).
  • Gongju.Contravariant — Contravariant syntax grids: positional pre-composition (precomposeAt @n, (-.), (-.*)), 2D function splicing (spliceAt @n @m), and nested contravariant functor mapping with alternating parity (contramapN @n, (<-$>), (<-$$>)).
  • Gongju.Monad — Two-phase positional monadic binding (bindPos @before @after, bindAt @n, (==<<), (=.=<<)), multi-slot monadic lifting masks (liftMask @'[MArg, PArg, MArg]), and arity-indexed Kleisli composition (liftPureN @n, bindKleisliN @n, (<=<.), (.>=>)).

Quick Start

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeApplications #-}

import Gongju.Core

main :: IO ()
main = do
  -- 1. Variadic composition over a 3-argument function:
  let add3 x y z = (x + y + z :: Int)
  print (compN @3 (* 2) add3 1 2 3) -- Prints 12

  -- 2. Permuting arguments of a function:
  let f x y z = (x, y, z)
  print (permute @'[2, 0, 1] f True 10 "gongju") -- Prints (10, "gongju", True)

  -- 3. Tape-driven composition:
  let comp = ((+ 1) .@ [P, P]) (+)
  print (comp 5 10) -- Prints 16

Zero-Cost Guarantee

Under GHC -O2, all combinators inline and simplify into primitive lambda applications with zero residual typeclass dictionaries, verified mechanically by bin/gongju-inspect-core.


License

Licensed under the European Union Public Licence (EUPL-1.2) or Apache License 2.0.