On this page
Prelude
| Copyright | (c) The University of Glasgow 2001 |
|---|---|
| License | BSD-style (see the file libraries/base/LICENSE) |
| Maintainer | libraries@haskell.org |
| Stability | stable |
| Portability | portable |
| Safe Haskell | Trustworthy |
| Language | Haskell2010 |
Description
The Prelude: a standard module. The Prelude is imported by default into all Haskell modules unless either there is an explicit import statement for it, or the NoImplicitPrelude extension is enabled.
Standard types, classes and related functions
Basic data types
Instances
| Data Bool Source | Since: base-4.0.0.0 |
|
Defined in Data.Data Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Bool -> c Bool Source gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Bool Source toConstr :: Bool -> Constr Source dataTypeOf :: Bool -> DataType Source dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Bool) Source dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Bool) Source gmapT :: (forall b. Data b => b -> b) -> Bool -> Bool Source gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Bool -> r Source gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Bool -> r Source gmapQ :: (forall d. Data d => d -> u) -> Bool -> [u] Source gmapQi :: Int -> (forall d. Data d => d -> u) -> Bool -> u Source gmapM :: Monad m => (forall d. Data d => d -> m d) -> Bool -> m Bool Source gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Bool -> m Bool Source gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Bool -> m Bool Source |
|
| Storable Bool Source | Since: base-2.1 |
|
Defined in Foreign.Storable |
|
| Bits Bool Source | Interpret Since: base-4.7.0.0 |
|
Defined in GHC.Bits Methods(.&.) :: Bool -> Bool -> Bool Source (.|.) :: Bool -> Bool -> Bool Source xor :: Bool -> Bool -> Bool Source complement :: Bool -> Bool Source shift :: Bool -> Int -> Bool Source rotate :: Bool -> Int -> Bool Source setBit :: Bool -> Int -> Bool Source clearBit :: Bool -> Int -> Bool Source complementBit :: Bool -> Int -> Bool Source testBit :: Bool -> Int -> Bool Source bitSizeMaybe :: Bool -> Maybe Int Source isSigned :: Bool -> Bool Source shiftL :: Bool -> Int -> Bool Source unsafeShiftL :: Bool -> Int -> Bool Source shiftR :: Bool -> Int -> Bool Source unsafeShiftR :: Bool -> Int -> Bool Source rotateL :: Bool -> Int -> Bool Source |
|
| FiniteBits Bool Source | Since: base-4.7.0.0 |
|
Defined in GHC.Bits MethodsfiniteBitSize :: Bool -> Int Source countLeadingZeros :: Bool -> Int Source countTrailingZeros :: Bool -> Int Source |
|
| Bounded Bool Source | Since: base-2.1 |
| Enum Bool Source | Since: base-2.1 |
| Generic Bool Source | |
| Ix Bool Source | Since: base-2.1 |
| Read Bool Source | Since: base-2.1 |
| Show Bool Source | Since: base-2.1 |
| Eq Bool | |
| Ord Bool | |
| type Rep Bool Source | Since: base-4.6.0.0 |
(&&) :: Bool -> Bool -> Bool infixr 3 Source
Boolean "and", lazy in the second argument
(||) :: Bool -> Bool -> Bool infixr 2 Source
Boolean "or", lazy in the second argument
Boolean "not"
otherwise is defined as the value True. It helps to make guards more readable. eg.
f x | x < 0 = ...
| otherwise = ...
The Maybe type encapsulates an optional value. A value of type Maybe a either contains a value of type a (represented as Just a), or it is empty (represented as Nothing). Using Maybe is a good way to deal with errors or exceptional cases without resorting to drastic measures such as error.
The Maybe type is also a monad. It is a simple kind of error monad, where all errors are represented by Nothing. A richer error monad can be built using the Either type.
Instances
| MonadFail Maybe Source | Since: base-4.9.0.0 |
|
Defined in Control.Monad.Fail |
|
| MonadFix Maybe Source | Since: base-2.1 |
|
Defined in Control.Monad.Fix |
|
| MonadZip Maybe Source | Since: base-4.8.0.0 |
| Foldable Maybe Source | Since: base-2.1 |
|
Defined in Data.Foldable Methodsfold :: Monoid m => Maybe m -> m Source foldMap :: Monoid m => (a -> m) -> Maybe a -> m Source foldMap' :: Monoid m => (a -> m) -> Maybe a -> m Source foldr :: (a -> b -> b) -> b -> Maybe a -> b Source foldr' :: (a -> b -> b) -> b -> Maybe a -> b Source foldl :: (b -> a -> b) -> b -> Maybe a -> b Source foldl' :: (b -> a -> b) -> b -> Maybe a -> b Source foldr1 :: (a -> a -> a) -> Maybe a -> a Source foldl1 :: (a -> a -> a) -> Maybe a -> a Source toList :: Maybe a -> [a] Source null :: Maybe a -> Bool Source length :: Maybe a -> Int Source elem :: Eq a => a -> Maybe a -> Bool Source maximum :: Ord a => Maybe a -> a Source minimum :: Ord a => Maybe a -> a Source |
|
| Eq1 Maybe Source | Since: base-4.9.0.0 |
| Ord1 Maybe Source | Since: base-4.9.0.0 |
|
Defined in Data.Functor.Classes |
|
| Read1 Maybe Source | Since: base-4.9.0.0 |
|
Defined in Data.Functor.Classes MethodsliftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Maybe a) Source liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Maybe a] Source liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Maybe a) Source liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Maybe a] Source |
|
| Show1 Maybe Source | Since: base-4.9.0.0 |
| Traversable Maybe Source | Since: base-2.1 |
| Alternative Maybe Source | Since: base-2.1 |
| Applicative Maybe Source | Since: base-2.1 |
| Functor Maybe Source | Since: base-2.1 |
| Monad Maybe Source | Since: base-2.1 |
| MonadPlus Maybe Source | Since: base-2.1 |
| Generic1 Maybe Source | |
| Data a => Data (Maybe a) Source | Since: base-4.0.0.0 |
|
Defined in Data.Data Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Maybe a -> c (Maybe a) Source gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Maybe a) Source toConstr :: Maybe a -> Constr Source dataTypeOf :: Maybe a -> DataType Source dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Maybe a)) Source dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Maybe a)) Source gmapT :: (forall b. Data b => b -> b) -> Maybe a -> Maybe a Source gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Maybe a -> r Source gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Maybe a -> r Source gmapQ :: (forall d. Data d => d -> u) -> Maybe a -> [u] Source gmapQi :: Int -> (forall d. Data d => d -> u) -> Maybe a -> u Source gmapM :: Monad m => (forall d. Data d => d -> m d) -> Maybe a -> m (Maybe a) Source gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Maybe a -> m (Maybe a) Source gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Maybe a -> m (Maybe a) Source |
|
| Semigroup a => Monoid (Maybe a) Source | Lift a semigroup into Since 4.11.0: constraint on inner Since: base-2.1 |
| Semigroup a => Semigroup (Maybe a) Source | Since: base-4.9.0.0 |
| Generic (Maybe a) Source | |
| Read a => Read (Maybe a) Source | Since: base-2.1 |
| Show a => Show (Maybe a) Source | Since: base-2.1 |
| Eq a => Eq (Maybe a) Source | Since: base-2.1 |
| Ord a => Ord (Maybe a) Source | Since: base-2.1 |
| type Rep1 Maybe Source | Since: base-4.6.0.0 |
| type Rep (Maybe a) Source | Since: base-4.6.0.0 |
|
Defined in GHC.Generics |
|
maybe :: b -> (a -> b) -> Maybe a -> b Source
The maybe function takes a default value, a function, and a Maybe value. If the Maybe value is Nothing, the function returns the default value. Otherwise, it applies the function to the value inside the Just and returns the result.
Examples
Basic usage:
>>> maybe False odd (Just 3)
True
>>> maybe False odd Nothing
False
Read an integer from a string using readMaybe. If we succeed, return twice the integer; that is, apply (*2) to it. If instead we fail to parse an integer, return 0 by default:
>>> import Text.Read ( readMaybe )
>>> maybe 0 (*2) (readMaybe "5")
10
>>> maybe 0 (*2) (readMaybe "")
0
Apply show to a Maybe Int. If we have Just n, we want to show the underlying Int n. But if we have Nothing, we return the empty string instead of (for example) "Nothing":
>>> maybe "" show (Just 5)
"5"
>>> maybe "" show Nothing
""
The Either type represents values with two possibilities: a value of type Either a b is either Left a or Right b.
The Either type is sometimes used to represent a value which is either correct or an error; by convention, the Left constructor is used to hold an error value and the Right constructor is used to hold a correct value (mnemonic: "right" also means "correct").
Examples
The type Either String Int is the type of values which can be either a String or an Int. The Left constructor can be used only on Strings, and the Right constructor can be used only on Ints:
>>> let s = Left "foo" :: Either String Int
>>> s
Left "foo"
>>> let n = Right 3 :: Either String Int
>>> n
Right 3
>>> :type s
s :: Either String Int
>>> :type n
n :: Either String Int
The fmap from our Functor instance will ignore Left values, but will apply the supplied function to values contained in a Right:
>>> let s = Left "foo" :: Either String Int
>>> let n = Right 3 :: Either String Int
>>> fmap (*2) s
Left "foo"
>>> fmap (*2) n
Right 6
The Monad instance for Either allows us to chain together multiple actions which may fail, and fail overall if any of the individual steps failed. First we'll write a function that can either parse an Int from a Char, or fail.
>>> import Data.Char ( digitToInt, isDigit )
>>> :{
let parseEither :: Char -> Either String Int
parseEither c
| isDigit c = Right (digitToInt c)
| otherwise = Left "parse error"
>>> :}
The following should work, since both '1' and '2' can be parsed as Ints.
>>> :{
let parseMultiple :: Either String Int
parseMultiple = do
x <- parseEither '1'
y <- parseEither '2'
return (x + y)
>>> :}
>>> parseMultiple
Right 3
But the following should fail overall, since the first operation where we attempt to parse 'm' as an Int will fail:
>>> :{
let parseMultiple :: Either String Int
parseMultiple = do
x <- parseEither 'm'
y <- parseEither '2'
return (x + y)
>>> :}
>>> parseMultiple
Left "parse error"
Instances
| Bifoldable Either Source | Since: base-4.10.0.0 |
| Bifunctor Either Source | Since: base-4.8.0.0 |
| Bitraversable Either Source | Since: base-4.10.0.0 |
|
Defined in Data.Bitraversable Methodsbitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Either a b -> f (Either c d) Source |
|
| Eq2 Either Source | Since: base-4.9.0.0 |
| Ord2 Either Source | Since: base-4.9.0.0 |
|
Defined in Data.Functor.Classes |
|
| Read2 Either Source | Since: base-4.9.0.0 |
|
Defined in Data.Functor.Classes MethodsliftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (Either a b) Source liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [Either a b] Source liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (Either a b) Source liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [Either a b] Source |
|
| Show2 Either Source | Since: base-4.9.0.0 |
|
Defined in Data.Functor.Classes |
|
| Generic1 (Either a :: Type -> Type) Source | |
| MonadFix (Either e) Source | Since: base-4.3.0.0 |
|
Defined in Control.Monad.Fix |
|
| Foldable (Either a) Source | Since: base-4.7.0.0 |
|
Defined in Data.Foldable Methodsfold :: Monoid m => Either a m -> m Source foldMap :: Monoid m => (a0 -> m) -> Either a a0 -> m Source foldMap' :: Monoid m => (a0 -> m) -> Either a a0 -> m Source foldr :: (a0 -> b -> b) -> b -> Either a a0 -> b Source foldr' :: (a0 -> b -> b) -> b -> Either a a0 -> b Source foldl :: (b -> a0 -> b) -> b -> Either a a0 -> b Source foldl' :: (b -> a0 -> b) -> b -> Either a a0 -> b Source foldr1 :: (a0 -> a0 -> a0) -> Either a a0 -> a0 Source foldl1 :: (a0 -> a0 -> a0) -> Either a a0 -> a0 Source toList :: Either a a0 -> [a0] Source null :: Either a a0 -> Bool Source length :: Either a a0 -> Int Source elem :: Eq a0 => a0 -> Either a a0 -> Bool Source maximum :: Ord a0 => Either a a0 -> a0 Source minimum :: Ord a0 => Either a a0 -> a0 Source |
|
| Eq a => Eq1 (Either a) Source | Since: base-4.9.0.0 |
| Ord a => Ord1 (Either a) Source | Since: base-4.9.0.0 |
|
Defined in Data.Functor.Classes |
|
| Read a => Read1 (Either a) Source | Since: base-4.9.0.0 |
|
Defined in Data.Functor.Classes MethodsliftReadsPrec :: (Int -> ReadS a0) -> ReadS [a0] -> Int -> ReadS (Either a a0) Source liftReadList :: (Int -> ReadS a0) -> ReadS [a0] -> ReadS [Either a a0] Source liftReadPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec (Either a a0) Source liftReadListPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec [Either a a0] Source |
|
| Show a => Show1 (Either a) Source | Since: base-4.9.0.0 |
| Traversable (Either a) Source | Since: base-4.7.0.0 |
|
Defined in Data.Traversable |
|
| Applicative (Either e) Source | Since: base-3.0 |
|
Defined in Data.Either |
|
| Functor (Either a) Source | Since: base-3.0 |
| Monad (Either e) Source | Since: base-4.4.0.0 |
| (Data a, Data b) => Data (Either a b) Source | Since: base-4.0.0.0 |
|
Defined in Data.Data Methodsgfoldl :: (forall d b0. Data d => c (d -> b0) -> d -> c b0) -> (forall g. g -> c g) -> Either a b -> c (Either a b) Source gunfold :: (forall b0 r. Data b0 => c (b0 -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Either a b) Source toConstr :: Either a b -> Constr Source dataTypeOf :: Either a b -> DataType Source dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Either a b)) Source dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Either a b)) Source gmapT :: (forall b0. Data b0 => b0 -> b0) -> Either a b -> Either a b Source gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Either a b -> r Source gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Either a b -> r Source gmapQ :: (forall d. Data d => d -> u) -> Either a b -> [u] Source gmapQi :: Int -> (forall d. Data d => d -> u) -> Either a b -> u Source gmapM :: Monad m => (forall d. Data d => d -> m d) -> Either a b -> m (Either a b) Source gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Either a b -> m (Either a b) Source gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Either a b -> m (Either a b) Source |
|
| Semigroup (Either a b) Source | Since: base-4.9.0.0 |
| Generic (Either a b) Source | |
| (Read a, Read b) => Read (Either a b) Source | Since: base-3.0 |
| (Show a, Show b) => Show (Either a b) Source | Since: base-3.0 |
| (Eq a, Eq b) => Eq (Either a b) Source | Since: base-2.1 |
| (Ord a, Ord b) => Ord (Either a b) Source | Since: base-2.1 |
|
Defined in Data.Either Methodscompare :: Either a b -> Either a b -> Ordering Source (<) :: Either a b -> Either a b -> Bool Source (<=) :: Either a b -> Either a b -> Bool Source (>) :: Either a b -> Either a b -> Bool Source (>=) :: Either a b -> Either a b -> Bool Source |
|
| type Rep1 (Either a :: Type -> Type) Source | Since: base-4.6.0.0 |
|
Defined in GHC.Generics
type Rep1 (Either a :: Type -> Type) = D1 ('MetaData "Either" "Data.Either" "base" 'False) (C1 ('MetaCons "Left" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)) :+: C1 ('MetaCons "Right" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1))
|
|
| type Rep (Either a b) Source | Since: base-4.6.0.0 |
|
Defined in GHC.Generics
type Rep (Either a b) = D1 ('MetaData "Either" "Data.Either" "base" 'False) (C1 ('MetaCons "Left" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)) :+: C1 ('MetaCons "Right" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 b)))
|
|
either :: (a -> c) -> (b -> c) -> Either a b -> c Source
Case analysis for the Either type. If the value is Left a, apply the first function to a; if it is Right b, apply the second function to b.
Examples
We create two values of type Either String Int, one using the Left constructor and another using the Right constructor. Then we apply "either" the length function (if we have a String) or the "times-two" function (if we have an Int):
>>> let s = Left "foo" :: Either String Int
>>> let n = Right 3 :: Either String Int
>>> either length (*2) s
3
>>> either length (*2) n
6
Instances
The character type Char is an enumeration whose values represent Unicode (or equivalently ISO/IEC 10646) code points (i.e. characters, see http://www.unicode.org/ for details). This set extends the ISO 8859-1 (Latin-1) character set (the first 256 characters), which is itself an extension of the ASCII character set (the first 128 characters). A character literal in Haskell has type Char.
To convert a Char to or from the corresponding Int value defined by Unicode, use toEnum and fromEnum from the Enum class respectively (or equivalently ord and chr).
Instances
| Data Char Source | Since: base-4.0.0.0 |
|
Defined in Data.Data Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Char -> c Char Source gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Char Source toConstr :: Char -> Constr Source dataTypeOf :: Char -> DataType Source dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Char) Source dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Char) Source gmapT :: (forall b. Data b => b -> b) -> Char -> Char Source gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Char -> r Source gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Char -> r Source gmapQ :: (forall d. Data d => d -> u) -> Char -> [u] Source gmapQi :: Int -> (forall d. Data d => d -> u) -> Char -> u Source gmapM :: Monad m => (forall d. Data d => d -> m d) -> Char -> m Char Source gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Char -> m Char Source gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Char -> m Char Source |
|
| Storable Char Source | Since: base-2.1 |
|
Defined in Foreign.Storable |
|
| Bounded Char Source | Since: base-2.1 |
| Enum Char Source | Since: base-2.1 |
| Ix Char Source | Since: base-2.1 |
| Read Char Source | Since: base-2.1 |
| Show Char Source | Since: base-2.1 |
| IsChar Char Source | Since: base-2.1 |
| PrintfArg Char Source | Since: base-2.1 |
|
Defined in Text.Printf |
|
| Eq Char | |
| Ord Char | |
| Generic1 (URec Char :: k -> Type) Source | |
| Foldable (UChar :: Type -> Type) Source | Since: base-4.9.0.0 |
|
Defined in Data.Foldable Methodsfold :: Monoid m => UChar m -> m Source foldMap :: Monoid m => (a -> m) -> UChar a -> m Source foldMap' :: Monoid m => (a -> m) -> UChar a -> m Source foldr :: (a -> b -> b) -> b -> UChar a -> b Source foldr' :: (a -> b -> b) -> b -> UChar a -> b Source foldl :: (b -> a -> b) -> b -> UChar a -> b Source foldl' :: (b -> a -> b) -> b -> UChar a -> b Source foldr1 :: (a -> a -> a) -> UChar a -> a Source foldl1 :: (a -> a -> a) -> UChar a -> a Source toList :: UChar a -> [a] Source null :: UChar a -> Bool Source length :: UChar a -> Int Source elem :: Eq a => a -> UChar a -> Bool Source maximum :: Ord a => UChar a -> a Source minimum :: Ord a => UChar a -> a Source |
|
| Traversable (UChar :: Type -> Type) Source | Since: base-4.9.0.0 |
| Functor (URec Char :: Type -> Type) Source | Since: base-4.9.0.0 |
| Generic (URec Char p) Source | |
| Show (URec Char p) Source | Since: base-4.9.0.0 |
| Eq (URec Char p) Source | Since: base-4.9.0.0 |
| Ord (URec Char p) Source | Since: base-4.9.0.0 |
|
Defined in GHC.Generics Methodscompare :: URec Char p -> URec Char p -> Ordering Source (<) :: URec Char p -> URec Char p -> Bool Source (<=) :: URec Char p -> URec Char p -> Bool Source (>) :: URec Char p -> URec Char p -> Bool Source (>=) :: URec Char p -> URec Char p -> Bool Source |
|
| data URec Char (p :: k) Source | Used for marking occurrences of Since: base-4.9.0.0 |
| type Compare (a :: Char) (b :: Char) Source | |
|
Defined in Data.Type.Ord |
|
| type Rep1 (URec Char :: k -> Type) Source | Since: base-4.9.0.0 |
|
Defined in GHC.Generics |
|
| type Rep (URec Char p) Source | Since: base-4.9.0.0 |
|
Defined in GHC.Generics |
|
A String is a list of characters. String constants in Haskell are values of type String.
See Data.List for operations on lists.
Tuples
Extract the first component of a pair.
Extract the second component of a pair.
curry :: ((a, b) -> c) -> a -> b -> c Source
curry converts an uncurried function to a curried function.
Examples
>>> curry fst 1 2
1
uncurry :: (a -> b -> c) -> (a, b) -> c Source
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]
Basic type classes
The Eq class defines equality (==) and inequality (/=). All the basic datatypes exported by the Prelude are instances of Eq, and Eq may be derived for any datatype whose constituents are also instances of Eq.
The Haskell Report defines no laws for Eq. However, instances are encouraged to follow these properties:
- Reflexivity
x == x=True- Symmetry
x == y=y == x- Transitivity
-
if
x == y && y == z=True, thenx == z=True - Extensionality
-
if
x == y=Trueandfis a function whose return type is an instance ofEq, thenf x == f y=True - Negation
x /= y=not (x == y)
Minimal complete definition: either == or /=.
Instances
| Eq ByteArray Source | Since: base-4.17.0.0 |
| Eq Constr Source | Equality of constructors Since: base-4.0.0.0 |
| Eq ConstrRep Source | Since: base-4.0.0.0 |
| Eq DataRep Source | Since: base-4.0.0.0 |
| Eq Fixity Source | Since: base-4.0.0.0 |
| Eq All Source | Since: base-2.1 |
| Eq Any Source | Since: base-2.1 |
| Eq SomeTypeRep Source | |
|
Defined in Data.Typeable.Internal Methods(==) :: SomeTypeRep -> SomeTypeRep -> Bool Source (/=) :: SomeTypeRep -> SomeTypeRep -> Bool Source |
|
| Eq Unique Source | |
| Eq Version Source | Since: base-2.1 |
| Eq Void Source | Since: base-4.8.0.0 |
| Eq Errno Source | Since: base-2.1 |
| Eq CBool Source | |
| Eq CChar Source | |
| Eq CClock Source | |
| Eq CDouble Source | |
| Eq CFloat Source | |
| Eq CInt Source | |
| Eq CIntMax Source | |
| Eq CIntPtr Source | |
| Eq CLLong Source | |
| Eq CLong Source | |
| Eq CPtrdiff Source | |
| Eq CSChar Source | |
| Eq CSUSeconds Source | |
|
Defined in Foreign.C.Types Methods(==) :: CSUSeconds -> CSUSeconds -> Bool Source (/=) :: CSUSeconds -> CSUSeconds -> Bool Source |
|
| Eq CShort Source | |
| Eq CSigAtomic Source | |
|
Defined in Foreign.C.Types Methods(==) :: CSigAtomic -> CSigAtomic -> Bool Source (/=) :: CSigAtomic -> CSigAtomic -> Bool Source |
|
| Eq CSize Source | |
| Eq CTime Source | |
| Eq CUChar Source | |
| Eq CUInt Source | |
| Eq CUIntMax Source | |
| Eq CUIntPtr Source | |
| Eq CULLong Source | |
| Eq CULong Source | |
| Eq CUSeconds Source | |
| Eq CUShort Source | |
| Eq CWchar Source | |
| Eq IntPtr Source | |
| Eq WordPtr Source | |
| Eq ByteOrder Source | Since: base-4.11.0.0 |
| Eq BlockReason Source | Since: base-4.3.0.0 |
|
Defined in GHC.Conc.Sync Methods(==) :: BlockReason -> BlockReason -> Bool Source (/=) :: BlockReason -> BlockReason -> Bool Source |
|
| Eq ThreadId Source | Since: base-4.2.0.0 |
| Eq ThreadStatus Source | Since: base-4.3.0.0 |
|
Defined in GHC.Conc.Sync Methods(==) :: ThreadStatus -> ThreadStatus -> Bool Source (/=) :: ThreadStatus -> ThreadStatus -> Bool Source |
|
| Eq Event Source | Since: base-4.4.0.0 |
| Eq Lifetime Source | Since: base-4.8.1.0 |
| Eq FdKey Source | Since: base-4.4.0.0 |
| Eq TimeoutKey Source | |
|
Defined in GHC.Event.TimeOut Methods(==) :: TimeoutKey -> TimeoutKey -> Bool Source (/=) :: TimeoutKey -> TimeoutKey -> Bool Source |
|
| Eq ErrorCall Source | Since: base-4.7.0.0 |
| Eq ArithException Source | Since: base-3.0 |
|
Defined in GHC.Exception.Type Methods(==) :: ArithException -> ArithException -> Bool Source (/=) :: ArithException -> ArithException -> Bool Source |
|
| Eq SpecConstrAnnotation Source | Since: base-4.3.0.0 |
|
Defined in GHC.Exts Methods(==) :: SpecConstrAnnotation -> SpecConstrAnnotation -> Bool Source (/=) :: SpecConstrAnnotation -> SpecConstrAnnotation -> Bool Source |
|
| Eq Fingerprint Source | Since: base-4.4.0.0 |
|
Defined in GHC.Fingerprint.Type Methods(==) :: Fingerprint -> Fingerprint -> Bool Source (/=) :: Fingerprint -> Fingerprint -> Bool Source |
|
| Eq Associativity Source | Since: base-4.6.0.0 |
|
Defined in GHC.Generics Methods(==) :: Associativity -> Associativity -> Bool Source (/=) :: Associativity -> Associativity -> Bool Source |
|
| Eq DecidedStrictness Source | Since: base-4.9.0.0 |
|
Defined in GHC.Generics Methods(==) :: DecidedStrictness -> DecidedStrictness -> Bool Source (/=) :: DecidedStrictness -> DecidedStrictness -> Bool Source |
|
| Eq Fixity Source | Since: base-4.6.0.0 |
| Eq SourceStrictness Source | Since: base-4.9.0.0 |
|
Defined in GHC.Generics Methods(==) :: SourceStrictness -> SourceStrictness -> Bool Source (/=) :: SourceStrictness -> SourceStrictness -> Bool Source |
|
| Eq SourceUnpackedness Source | Since: base-4.9.0.0 |
|
Defined in GHC.Generics Methods(==) :: SourceUnpackedness -> SourceUnpackedness -> Bool Source (/=) :: SourceUnpackedness -> SourceUnpackedness -> Bool Source |
|
| Eq MaskingState Source | Since: base-4.3.0.0 |
|
Defined in GHC.IO Methods(==) :: MaskingState -> MaskingState -> Bool Source (/=) :: MaskingState -> MaskingState -> Bool Source |
|
| Eq BufferState Source | Since: base-4.2.0.0 |
|
Defined in GHC.IO.Buffer Methods(==) :: BufferState -> BufferState -> Bool Source (/=) :: BufferState -> BufferState -> Bool Source |
|
| Eq IODeviceType Source | Since: base-4.2.0.0 |
|
Defined in GHC.IO.Device Methods(==) :: IODeviceType -> IODeviceType -> Bool Source (/=) :: IODeviceType -> IODeviceType -> Bool Source |
|
| Eq SeekMode Source | Since: base-4.2.0.0 |
| Eq CodingProgress Source | Since: base-4.4.0.0 |
|
Defined in GHC.IO.Encoding.Types Methods(==) :: CodingProgress -> CodingProgress -> Bool Source (/=) :: CodingProgress -> CodingProgress -> Bool Source |
|
| Eq ArrayException Source | Since: base-4.2.0.0 |
|
Defined in GHC.IO.Exception Methods(==) :: ArrayException -> ArrayException -> Bool Source (/=) :: ArrayException -> ArrayException -> Bool Source |
|
| Eq AsyncException Source | Since: base-4.2.0.0 |
|
Defined in GHC.IO.Exception Methods(==) :: AsyncException -> AsyncException -> Bool Source (/=) :: AsyncException -> AsyncException -> Bool Source |
|
| Eq ExitCode Source | |
| Eq IOErrorType Source | Since: base-4.1.0.0 |
|
Defined in GHC.IO.Exception Methods(==) :: IOErrorType -> IOErrorType -> Bool Source (/=) :: IOErrorType -> IOErrorType -> Bool Source |
|
| Eq IOException Source | Since: base-4.1.0.0 |
|
Defined in GHC.IO.Exception Methods(==) :: IOException -> IOException -> Bool Source (/=) :: IOException -> IOException -> Bool Source |
|
| Eq HandlePosn Source | Since: base-4.1.0.0 |
|
Defined in GHC.IO.Handle Methods(==) :: HandlePosn -> HandlePosn -> Bool Source (/=) :: HandlePosn -> HandlePosn -> Bool Source |
|
| Eq BufferMode Source | Since: base-4.2.0.0 |
|
Defined in GHC.IO.Handle.Types Methods(==) :: BufferMode -> BufferMode -> Bool Source (/=) :: BufferMode -> BufferMode -> Bool Source |
|
| Eq Handle Source | Since: base-4.1.0.0 |
| Eq Newline Source | Since: base-4.2.0.0 |
| Eq NewlineMode Source | Since: base-4.2.0.0 |
|
Defined in GHC.IO.Handle.Types Methods(==) :: NewlineMode -> NewlineMode -> Bool Source (/=) :: NewlineMode -> NewlineMode -> Bool Source |
|
| Eq IOMode Source | Since: base-4.2.0.0 |
| Eq Int16 Source | Since: base-2.1 |
| Eq Int32 Source | Since: base-2.1 |
| Eq Int64 Source | Since: base-2.1 |
| Eq Int8 Source | Since: base-2.1 |
| Eq IoSubSystem Source | |
|
Defined in GHC.RTS.Flags Methods(==) :: IoSubSystem -> IoSubSystem -> Bool Source (/=) :: IoSubSystem -> IoSubSystem -> Bool Source |
|
| Eq InfoProv Source | |
| Eq StackEntry Source | |
|
Defined in GHC.Stack.CloneStack Methods(==) :: StackEntry -> StackEntry -> Bool Source (/=) :: StackEntry -> StackEntry -> Bool Source |
|
| Eq SrcLoc Source | Since: base-4.9.0.0 |
| Eq SomeChar Source | |
| Eq SomeSymbol Source | Since: base-4.7.0.0 |
|
Defined in GHC.TypeLits Methods(==) :: SomeSymbol -> SomeSymbol -> Bool Source (/=) :: SomeSymbol -> SomeSymbol -> Bool Source |
|
| Eq SomeNat Source | Since: base-4.7.0.0 |
| Eq GeneralCategory Source | Since: base-2.1 |
|
Defined in GHC.Unicode Methods(==) :: GeneralCategory -> GeneralCategory -> Bool Source (/=) :: GeneralCategory -> GeneralCategory -> Bool Source |
|
| Eq Word16 Source | Since: base-2.1 |
| Eq Word32 Source | Since: base-2.1 |
| Eq Word64 Source | Since: base-2.1 |
| Eq Word8 Source | Since: base-2.1 |
| Eq CBlkCnt Source | |
| Eq CBlkSize Source | |
| Eq CCc Source | |
| Eq CClockId Source | |
| Eq CDev Source | |
| Eq CFsBlkCnt Source | |
| Eq CFsFilCnt Source | |
| Eq CGid Source | |
| Eq CId Source | |
| Eq CIno Source | |
| Eq CKey Source | |
| Eq CMode Source | |
| Eq CNfds Source | |
| Eq CNlink Source | |
| Eq COff Source | |
| Eq CPid Source | |
| Eq CRLim Source | |
| Eq CSocklen Source | |
| Eq CSpeed Source | |
| Eq CSsize Source | |
| Eq CTcflag Source | |
| Eq CTimer Source | |
| Eq CUid Source | |
| Eq Fd Source | |
| Eq Timeout Source | |
| Eq Lexeme Source | Since: base-2.1 |
| Eq Number Source | Since: base-4.6.0.0 |
| Eq BigNat | |
| Eq Module | |
| Eq Ordering | |
| Eq TrName | |
| Eq TyCon | |
| Eq Integer | |
| Eq Natural | |
| Eq () | |
| Eq Bool | |
| Eq Char | |
| Eq Double | Note that due to the presence of Also note that |
| Eq Float | Note that due to the presence of Also note that |
| Eq Int | |
| Eq Word | |
| Eq a => Eq (ZipList a) Source | Since: base-4.7.0.0 |
| Eq (Chan a) Source | Since: base-4.4.0.0 |
| Eq (MutableByteArray s) Source | Since: base-4.17.0.0 |
|
Defined in Data.Array.Byte Methods(==) :: MutableByteArray s -> MutableByteArray s -> Bool Source (/=) :: MutableByteArray s -> MutableByteArray s -> Bool Source |
|
| Eq a => Eq (And a) Source | Since: base-4.16 |
| Eq a => Eq (Iff a) Source | Since: base-4.16 |
| Eq a => Eq (Ior a) Source | Since: base-4.16 |
| Eq a => Eq (Xor a) Source | Since: base-4.16 |
| Eq a => Eq (Complex a) Source | Since: base-2.1 |
| Eq a => Eq (Identity a) Source | Since: base-4.8.0.0 |
| Eq a => Eq (First a) Source | Since: base-2.1 |
| Eq a => Eq (Last a) Source | Since: base-2.1 |
| Eq a => Eq (Down a) Source | Since: base-4.6.0.0 |
| Eq a => Eq (First a) Source | Since: base-4.9.0.0 |
| Eq a => Eq (Last a) Source | Since: base-4.9.0.0 |
| Eq a => Eq (Max a) Source | Since: base-4.9.0.0 |
| Eq a => Eq (Min a) Source | Since: base-4.9.0.0 |
| Eq m => Eq (WrappedMonoid m) Source | Since: base-4.9.0.0 |
|
Defined in Data.Semigroup Methods(==) :: WrappedMonoid m -> WrappedMonoid m -> Bool Source (/=) :: WrappedMonoid m -> WrappedMonoid m -> Bool Source |
|
| Eq a => Eq (Dual a) Source | Since: base-2.1 |
| Eq a => Eq (Product a) Source | Since: base-2.1 |
| Eq a => Eq (Sum a) Source | Since: base-2.1 |
| Eq (TVar a) Source | Since: base-4.8.0.0 |
| Eq (ForeignPtr a) Source | Since: base-2.1 |
|
Defined in GHC.ForeignPtr Methods(==) :: ForeignPtr a -> ForeignPtr a -> Bool Source (/=) :: ForeignPtr a -> ForeignPtr a -> Bool Source |
|
| Eq p => Eq (Par1 p) Source | Since: base-4.7.0.0 |
| Eq (IORef a) Source | Pointer equality. Since: base-4.0.0.0 |
| Eq (MVar a) Source | Since: base-4.1.0.0 |
| Eq (FunPtr a) Source | |
| Eq (Ptr a) Source | Since: base-2.1 |
| Eq a => Eq (Ratio a) Source | Since: base-2.1 |
| Eq (StablePtr a) Source | Since: base-2.1 |
| Eq (StableName a) Source | Since: base-2.1 |
|
Defined in GHC.StableName Methods(==) :: StableName a -> StableName a -> Bool Source (/=) :: StableName a -> StableName a -> Bool Source |
|
| Eq a => Eq (NonEmpty a) Source | Since: base-4.9.0.0 |
| Eq a => Eq (Maybe a) Source | Since: base-2.1 |
| Eq a => Eq (a) | |
| Eq a => Eq [a] | |
| (Eq a, Eq b) => Eq (Either a b) Source | Since: base-2.1 |
| Eq (Fixed a) Source | Since: base-2.1 |
| Eq (Proxy s) Source | Since: base-4.7.0.0 |
| Eq a => Eq (Arg a b) Source | Since: base-4.9.0.0 |
| Eq (TypeRep a) Source | Since: base-2.1 |
| (Ix i, Eq e) => Eq (Array i e) Source | Since: base-2.1 |
| Eq (U1 p) Source | Since: base-4.9.0.0 |
| Eq (V1 p) Source | Since: base-4.9.0.0 |
| Eq (IOArray i e) Source | Since: base-4.1.0.0 |
| Eq (STRef s a) Source | Pointer equality. Since: base-2.1 |
| (Eq a, Eq b) => Eq (a, b) | |
| Eq a => Eq (Const a b) Source | Since: base-4.9.0.0 |
| Eq (f a) => Eq (Ap f a) Source | Since: base-4.12.0.0 |
| Eq (f a) => Eq (Alt f a) Source | Since: base-4.8.0.0 |
| Eq (Coercion a b) Source | Since: base-4.7.0.0 |
| Eq (a :~: b) Source | Since: base-4.7.0.0 |
| Eq (OrderingI a b) Source | |
| Eq (STArray s i e) Source | Since: base-2.1 |
| Eq (f p) => Eq (Rec1 f p) Source | Since: base-4.7.0.0 |
| Eq (URec (Ptr ()) p) Source | Since: base-4.9.0.0 |
| Eq (URec Char p) Source | Since: base-4.9.0.0 |
| Eq (URec Double p) Source | Since: base-4.9.0.0 |
| Eq (URec Float p) Source | |
| Eq (URec Int p) Source | Since: base-4.9.0.0 |
| Eq (URec Word p) Source | Since: base-4.9.0.0 |
| (Eq a, Eq b, Eq c) => Eq (a, b, c) | |
| (Eq1 f, Eq1 g, Eq a) => Eq (Product f g a) Source | Since: base-4.9.0.0 |
| (Eq1 f, Eq1 g, Eq a) => Eq (Sum f g a) Source | Since: base-4.9.0.0 |
| Eq (a :~~: b) Source | Since: base-4.10.0.0 |
| (Eq (f p), Eq (g p)) => Eq ((f :*: g) p) Source | Since: base-4.7.0.0 |
| (Eq (f p), Eq (g p)) => Eq ((f :+: g) p) Source | Since: base-4.7.0.0 |
| Eq c => Eq (K1 i c p) Source | Since: base-4.7.0.0 |
| (Eq a, Eq b, Eq c, Eq d) => Eq (a, b, c, d) | |
| (Eq1 f, Eq1 g, Eq a) => Eq (Compose f g a) Source | Since: base-4.9.0.0 |
| Eq (f (g p)) => Eq ((f :.: g) p) Source | Since: base-4.7.0.0 |
| Eq (f p) => Eq (M1 i c f p) Source | Since: base-4.7.0.0 |
| (Eq a, Eq b, Eq c, Eq d, Eq e) => Eq (a, b, c, d, e) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f) => Eq (a, b, c, d, e, f) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g) => Eq (a, b, c, d, e, f, g) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h) => Eq (a, b, c, d, e, f, g, h) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i) => Eq (a, b, c, d, e, f, g, h, i) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j) => Eq (a, b, c, d, e, f, g, h, i, j) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k) => Eq (a, b, c, d, e, f, g, h, i, j, k) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l) => Eq (a, b, c, d, e, f, g, h, i, j, k, l) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n) | |
| (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) | |
class Eq a => Ord a where Source
The Ord class is used for totally ordered datatypes.
Instances of Ord can be derived for any user-defined datatype whose constituent types are in Ord. The declared order of the constructors in the data declaration determines the ordering in derived Ord instances. The Ordering datatype allows a single comparison to determine the precise ordering of two objects.
Ord, as defined by the Haskell report, implements a total order and has the following properties:
- Comparability
x <= y || y <= x=True- Transitivity
-
if
x <= y && y <= z=True, thenx <= z=True - Reflexivity
x <= x=True- Antisymmetry
-
if
x <= y && y <= x=True, thenx == y=True
The following operator interactions are expected to hold:
x >= y=y <= xx < y=x <= y && x /= yx > y=y < xx < y=compare x y == LTx > y=compare x y == GTx == y=compare x y == EQmin x y == if x <= y then x else y=Truemax x y == if x >= y then x else y=True
Note that (7.) and (8.) do not require min and max to return either of their arguments. The result is merely required to equal one of the arguments in terms of (==).
Minimal complete definition: either compare or <=. Using compare can be more efficient for complex types.
Methods
compare :: a -> a -> Ordering Source
(<) :: a -> a -> Bool infix 4 Source
(<=) :: a -> a -> Bool infix 4 Source
(>) :: a -> a -> Bool infix 4 Source