# tuple-classes [![Hackage](https://img.shields.io/hackage/v/tuple-classes)](https://hackage.haskell.org/package/tuple-classes) 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 `Iso`s instead❩ * ❨Designed to complement the popular [strict](https://hackage.haskell.org/package/strict) package❩ * ❨`StrictTuple3` ❟ `StrictTuple4` ❟ ... up to `StrictTuple9` provided❩ * ❨More instances than you can shake a stick at❩ * ❨`Strict`❩ * ❨`Each` ❨`each`❩ and `Field1` ❨`_1`❩ ❟ `Field2` ❨`_2`❩ ❟ etc.❩ * ❨Pragmatic re-exports❩ ```haskell {-# 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 ``` ```haskell {-# 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.](https://hackage-content.haskell.org/package/lens-5.3.6/docs/Control-Lens-Tuple.html) and [`Each`](https://hackage-content.haskell.org/package/lens-5.3.6/docs/Control-Lens-Each.html#t:Each) * Lennart Augustsson's [`Curry`](https://hackage.haskell.org/package/tuple-0.3.0.2/docs/Data-Tuple-Curry.html) class * Mitchell Rosen's [strict-tuple](https://hackage.haskell.org/package/strict-tuple-0.1.5.4/docs/Data-Tuple-Strict.html) 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](https://bin.mangoiv.com/note?id=d204d07f-6292-4eb7-9aff-4cabc78394b9) 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](https://www.apache.org/licenses/LICENSE-2.0.html) ## Main Author ©2026 Steven Shuck