Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Tuple

Lean: Hale.Base.Tuple | Haskell: Data.Tuple + Prelude

Overview

Pair operations: swap, map components, curry/uncurry. Provides bidirectional conversions between curried and uncurried function forms.

API Mapping

LeanHaskellKind
Tuple.swapswapFunction
Tuple.mapFstfirst (Control.Arrow)Function
Tuple.mapSndsecondFunction
Tuple.bimapbimapFunction
Tuple.currycurryFunction
Tuple.uncurryuncurryFunction

Instances

None (standalone functions on Prod).

Proofs & Guarantees

  • swap_swapswap (swap p) = p (involution)
  • curry_uncurrycurry (uncurry f) = f
  • uncurry_curryuncurry (curry f) = f
  • bimap_idbimap id id = id
  • bimap_compbimap (f1 . f2) (g1 . g2) = bimap f1 g1 . bimap f2 g2
  • mapFst_eq_bimapmapFst f = bimap f id
  • mapSnd_eq_bimapmapSnd f = bimap id f

Example

-- Curry converts a function on pairs to a curried function
Tuple.curry (fun p => p.1 + p.2) 2 3
-- => 5