@hackage tuple-classes1.0.3

Working with n-ary tuples and functions; strict tuples

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