1----------------------------------------------------------------------------- 2-- | 3-- Module : Data.Strict.Tuple 4-- Copyright : (c) 2006-2007 Roman Leshchinskiy 5-- License : BSD-style (see the file LICENSE) 6-- 7-- Maintainer : Roman Leshchinskiy <rl@cse.unsw.edu.au> 8-- Stability : experimental 9-- Portability : portable 10-- 11-- Strict pairs. 12-- 13-- Same as regular Haskell pairs, but @(x :*: _|_) = (_|_ :*: y) = _|_@ 14-- 15----------------------------------------------------------------------------- 16 17{-# OPTIONS_GHC -fglasgow-exts #-} 18 19module Data.Strict.Tuple ( 20 Pair(..) 21#ifndef __HADDOCK__ 22#ifdef __GLASGOW_HASKELL__ 23 , (:!:) 24#endif 25#endif 26 , fst 27 , snd 28 , curry 29 , uncurry 30) where 31 32import Prelude hiding( fst, snd, curry, uncurry ) 33import Data.Array (Ix) 34 35infixl 2 :!: 36 37-- | The type of strict pairs. 38data Pair a b = !a :!: !b deriving(Eq, Ord, Show, Read, Bounded, Ix) 39 40#ifndef __HADDOCK__ 41#ifdef __GLASGOW_HASKELL__ 42-- This gives a nicer syntax for the type but only works in GHC for now. 43type (:!:) = Pair 44#endif 45#endif 46 47-- | Extract the first component of a strict pair. 48fst :: Pair a b -> a 49fst (x :!: _) = x 50 51-- | Extract the second component of a strict pair. 52snd :: Pair a b -> b 53snd (_ :!: y) = y 54 55-- | Curry a function on strict pairs. 56curry :: (Pair a b -> c) -> a -> b -> c 57curry f x y = f (x :!: y) 58 59-- | Convert a curried function to a function on strict pairs. 60uncurry :: (a -> b -> c) -> Pair a b -> c 61uncurry f (x :!: y) = f x y 62 63