Movatterモバイル変換
[0]ホーム
{-# LANGUAGE Trustworthy #-}{-# LANGUAGE NoImplicitPrelude #-}------------------------------------------------------------------------------- |-- Module : Data.Tuple-- Copyright : (c) The University of Glasgow 2001-- License : BSD-style (see the file libraries/base/LICENSE)---- Maintainer : libraries@haskell.org-- Stability : experimental-- Portability : portable---- Functions associated with the tuple data types.-------------------------------------------------------------------------------moduleData.Tuple(fst,snd,curry,uncurry,swap)whereimportGHC.Base()-- Note [Depend on GHC.Tuple]default()-- Double isn't available yet-- ----------------------------------------------------------------------------- Standard functions over tuples-- | Extract the first component of a pair.fst::(a,b)->afst :: (a, b) -> afst(ax,b_)=ax-- | Extract the second component of a pair.snd::(a,b)->bsnd :: (a, b) -> bsnd(a_,by)=by-- | 'curry' converts an uncurried function to a curried function.---- ==== __Examples__---- >>> curry fst 1 2-- 1curry::((a,b)->c)->a->b->ccurry :: ((a, b) -> c) -> a -> b -> ccurry(a, b) -> cfaxby=(a, b) -> cf(ax,by)-- | 'uncurry' converts a curried function to a function on pairs.---- ==== __Examples__---- >>> uncurry (+) (1,2)-- 3---- >>> uncurry ($) (show, 1)-- "1"---- >>> map (uncurry max) [(1,2), (3,4), (6,8)]-- [2,4,8]uncurry::(a->b->c)->((a,b)->c)uncurry :: (a -> b -> c) -> (a, b) -> cuncurrya -> b -> cf(a, b)p=a -> b -> cf((a, b) -> aforall a b. (a, b) -> afst(a, b)p)((a, b) -> bforall a b. (a, b) -> bsnd(a, b)p)-- | Swap the components of a pair.swap::(a,b)->(b,a)swap :: (a, b) -> (b, a)swap(aa,bb)=(bb,aa)-- $setup-- >>> import Prelude hiding (curry, uncurry, fst, snd)
[8]ページ先頭