tuple-classes: Working with n-ary tuples and functions; strict tuples

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

Please see the README on Codeberg at https://codeberg.org/sjshuck/tuple-classes#readme


[Skip to Readme]

Modules

[Index] [Quick Jump]

Flags

Automatic Flags
NameDescriptionDefault
lens

Use the full lens library instead of microlens.

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 1.0.0, 1.0.1, 1.0.2, 1.0.3
Change log CHANGELOG.md
Dependencies assoc, base (>=4.9 && <5), binary, deepseq, hashable, lens, microlens, strict, template-haskell [details]
License Apache-2.0
Copyright 2026 Steven Shuck
Author Steven Shuck
Maintainer stevenjshuck@gmail.com
Uploaded by SShuck at 2026-07-24T23:23:44Z
Category data
Home page https://codeberg.org/sjshuck/tuple-classes#readme
Bug tracker https://codeberg.org/sjshuck/tuple-classes/issues
Source repo head: git clone https://codeberg.org/sjshuck/tuple-classes
Distributions
Downloads 13 total (13 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-07-24 [all 1 reports]

Readme for tuple-classes-1.0.3

[back to package description]

tuple-classes

Hackage

Haskell facilities for manipulating n-ary tuples and functions.

  • ❨Generalized uncurrying and un-uncurrying❩
  • ❨Inserting and removing fields❩
  • ❨van Laarhoven optics ❟ courtesy microlens❩
    • ❨Build with flag tuple-classes:lens for Isos instead❩
  • ❨Designed to complement the popular strict package❩
  • StrictTuple3StrictTuple4 ❟ ... up to StrictTuple9 provided❩
  • ❨More instances than you can shake a stick at❩
    • Strict
    • Eacheach❩ and Field1_1❩ ❟ Field2_2❩ ❟ etc.❩
  • ❨Pragmatic re-exports❩
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeApplications #-}

import Data.Tuple.Classes (uncurriedN')
import Lens.Micro         (over)

-- Function wrapper that expects a unary function
printArgAndRun :: (Show a) => (a -> IO b) -> a -> IO b
printArgAndRun f x = do
    print x
    f x

-- But we have a ternary function
printTitleAndSum :: String -> Int -> Int -> IO ()
printTitleAndSum title i j = do
    putStrLn title
    print $ i + j

-- We can adapt it
printArgsTitleAndSum :: String -> Int -> Int -> IO ()
printArgsTitleAndSum = over (uncurriedN' @3) printArgAndRun printTitleAndSum

main :: IO ()
main = printArgsTitleAndSum "Important identity" 26885 15184
StrictTuple3 "Important identity" 26885 15184
Important identity
42069
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeApplications #-}

import Data.Tuple.Classes (TupleAt(..))

consTuple :: (TupleAt 1 a t u) => a -> t -> u
consTuple = tupleInsert @1
infixr `consTuple`

main :: IO ()
main = print $ 'x' `consTuple` False `consTuple` ("sequitur", "quodlibet")
('x',False,"sequitur","quodlibet")

Prior art

  • Edward Kmett's lens's Field1 etc. and Each
  • Lennart Augustsson's Curry class
  • Mitchell Rosen's strict-tuple which unfortunately would need some unnecessary-looking breaking changes to suit this library:
    • Removing Biapplicative instances in order to not depend on the heavy bifunctors package
    • Removing T1 and T2 which conflict with the much more supported Identity and Pair
  • mangoiv's proof-of-concept related to keyword args and arbitrary function arity

Credit to mango for suggesting the limitations of that approach and indirectly shaping this library's design.

LLM contribution policy

https://en.wikipedia.org/wiki/TESCREAL

License

Apache 2.0

Main Author

©2026 Steven Shuck