base-4.0.0.0: Basic librariesSource codeContentsIndex
Prelude
Portabilityportable
Stabilitystable
Maintainerlibraries@haskell.org
Contents
Standard types, classes and related functions
Basic data types
Tuples
Basic type classes
Numbers
Numeric types
Numeric type classes
Numeric functions
Monads and functors
Miscellaneous functions
List operations
Reducing lists (folds)
Special folds
Building lists
Scans
Infinite lists
Sublists
Searching lists
Zipping and unzipping lists
Functions on strings
Converting to and from String
Converting to String
Converting from String
Basic Input and output
Simple I/O operations
Output functions
Input functions
Files
Exception handling in the I/O monad
Description
The Prelude: a standard module imported by default into all Haskell modules. For more documentation, see the Haskell 98 Report http://www.haskell.org/onlinereport/.
Synopsis
(&&) :: Bool -> Bool -> Bool
(||) :: Bool -> Bool -> Bool
not :: Bool -> Bool
otherwise :: Bool
data Maybe a
= Nothing
| Just a
maybe :: b -> (a -> b) -> Maybe a -> b
data Either a b
= Left a
| Right b
either :: (a -> c) -> (b -> c) -> Either a b -> c
type String = [Char]
fst :: (a, b) -> a
snd :: (a, b) -> b
curry :: ((a, b) -> c) -> a -> b -> c
uncurry :: (a -> b -> c) -> (a, b) -> c
class Eq a where
(==) :: a -> a -> Bool
(/=) :: a -> a -> Bool
class Eq a => Ord a where
compare :: a -> a -> Ordering
(<) :: a -> a -> Bool
(>=) :: a -> a -> Bool
(>) :: a -> a -> Bool
(<=) :: a -> a -> Bool
max :: a -> a -> a
min :: a -> a -> a
class Enum a where
succ :: a -> a
pred :: a -> a
toEnum :: Int -> a
fromEnum :: a -> Int
enumFrom :: a -> [a]
enumFromThen :: a -> a -> [a]
enumFromTo :: a -> a -> [a]
enumFromThenTo :: a -> a -> a -> [a]
class Bounded a where
minBound :: a
maxBound :: a
type Rational = Ratio Integer
class (Eq a, Show a) => Num a where
(+) :: a -> a -> a
(*) :: a -> a -> a
(-) :: a -> a -> a
negate :: a -> a
abs :: a -> a
signum :: a -> a
fromInteger :: Integer -> a
class (Num a, Ord a) => Real a where
toRational :: a -> Rational
class (Real a, Enum a) => Integral a where
quot :: a -> a -> a
rem :: a -> a -> a
div :: a -> a -> a
mod :: a -> a -> a
quotRem :: a -> a -> (a, a)
divMod :: a -> a -> (a, a)
toInteger :: a -> Integer
class Num a => Fractional a where
(/) :: a -> a -> a
recip :: a -> a
fromRational :: Rational -> a
class Fractional a => Floating a where
pi :: a
exp :: a -> a
sqrt :: a -> a
log :: a -> a
(**) :: a -> a -> a
logBase :: a -> a -> a
sin :: a -> a
tan :: a -> a
cos :: a -> a
asin :: a -> a
atan :: a -> a
acos :: a -> a
sinh :: a -> a
tanh :: a -> a
cosh :: a -> a
asinh :: a -> a
atanh :: a -> a
acosh :: a -> a
class (Real a, Fractional a) => RealFrac a where
properFraction :: Integral b => a -> (b, a)
truncate :: Integral b => a -> b
round :: Integral b => a -> b
ceiling :: Integral b => a -> b
floor :: Integral b => a -> b
class (RealFrac a, Floating a) => RealFloat a where
floatRadix :: a -> Integer
floatDigits :: a -> Int
floatRange :: a -> (Int, Int)
decodeFloat :: a -> (Integer, Int)
encodeFloat :: Integer -> Int -> a
exponent :: a -> Int
significand :: a -> a
scaleFloat :: Int -> a -> a
isNaN :: a -> Bool
isInfinite :: a -> Bool
isDenormalized :: a -> Bool
isNegativeZero :: a -> Bool
isIEEE :: a -> Bool
atan2 :: a -> a -> a
subtract :: Num a => a -> a -> a
odd :: Integral a => a -> Bool
gcd :: Integral a => a -> a -> a
lcm :: Integral a => a -> a -> a
(^) :: (Num a, Integral b) => a -> b -> a
(^^) :: (Fractional a, Integral b) => a -> b -> a
fromIntegral :: (Integral a, Num b) => a -> b
realToFrac :: (Real a, Fractional b) => a -> b
class Monad m where
(>>=) :: forall a b. m a -> (a -> m b) -> m b
(>>) :: forall a b. m a -> m b -> m b
return :: a -> m a
fail :: String -> m a
class Functor f where
fmap :: (a -> b) -> f a -> f b
mapM :: Monad m => (a -> m b) -> [a] -> m [b]
mapM_ :: Monad m => (a -> m b) -> [a] -> m ()
sequence :: Monad m => [m a] -> m [a]
sequence_ :: Monad m => [m a] -> m ()
(=<<) :: Monad m => (a -> m b) -> m a -> m b
id :: a -> a
const :: a -> b -> a
(.) :: (b -> c) -> (a -> b) -> a -> c
flip :: (a -> b -> c) -> b -> a -> c
($) :: (a -> b) -> a -> b
until :: (a -> Bool) -> (a -> a) -> a -> a
asTypeOf :: a -> a -> a
error :: [Char] -> a
undefined :: a
($!) :: (a -> b) -> a -> b
map :: (a -> b) -> [a] -> [b]
(++) :: [a] -> [a] -> [a]
filter :: (a -> Bool) -> [a] -> [a]
head :: [a] -> a
last :: [a] -> a
tail :: [a] -> [a]
init :: [a] -> [a]
null :: [a] -> Bool
length :: [a] -> Int
(!!) :: [a] -> Int -> a
reverse :: [a] -> [a]
foldl :: (a -> b -> a) -> a -> [b] -> a
foldl1 :: (a -> a -> a) -> [a] -> a
foldr :: (a -> b -> b) -> b -> [a] -> b
foldr1 :: (a -> a -> a) -> [a] -> a
and :: [Bool] -> Bool
or :: [Bool] -> Bool
any :: (a -> Bool) -> [a] -> Bool
all :: (a -> Bool) -> [a] -> Bool
sum :: Num a => [a] -> a
product :: Num a => [a] -> a
concat :: [[a]] -> [a]
concatMap :: (a -> [b]) -> [a] -> [b]
maximum :: Ord a => [a] -> a
minimum :: Ord a => [a] -> a
scanl :: (a -> b -> a) -> a -> [b] -> [a]
scanl1 :: (a -> a -> a) -> [a] -> [a]
scanr :: (a -> b -> b) -> b -> [a] -> [b]
scanr1 :: (a -> a -> a) -> [a] -> [a]
iterate :: (a -> a) -> a -> [a]
repeat :: a -> [a]
replicate :: Int -> a -> [a]
cycle :: [a] -> [a]
take :: Int -> [a] -> [a]
drop :: Int -> [a] -> [a]
splitAt :: Int -> [a] -> ([a], [a])
takeWhile :: (a -> Bool) -> [a] -> [a]
dropWhile :: (a -> Bool) -> [a] -> [a]
span :: (a -> Bool) -> [a] -> ([a], [a])
break :: (a -> Bool) -> [a] -> ([a], [a])
elem :: Eq a => a -> [a] -> Bool
notElem :: Eq a => a -> [a] -> Bool
lookup :: Eq a => a -> [(a, b)] -> Maybe b
zip :: [a] -> [b] -> [(a, b)]
zip3 :: [a] -> [b] -> [c] -> [(a, b, c)]
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
unzip :: [(a, b)] -> ([a], [b])
unzip3 :: [(a, b, c)] -> ([a], [b], [c])
lines :: String -> [String]
words :: String -> [String]
unlines :: [String] -> String
unwords :: [String] -> String
type ShowS = String -> String
class Show a where
showsPrec :: Int -> a -> ShowS
show :: a -> String
showList :: [a] -> ShowS
shows :: Show a => a -> ShowS
showChar :: Char -> ShowS
showString :: String -> ShowS
showParen :: Bool -> ShowS -> ShowS
type ReadS a = String -> [(a, String)]
class Read a where
readsPrec :: Int -> ReadS a
readList :: ReadS [a]
reads :: Read a => ReadS a
readParen :: Bool -> ReadS a -> ReadS a
read :: Read a => String -> a
lex :: ReadS String
data IO a
putChar :: Char -> IO ()
putStr :: String -> IO ()
putStrLn :: String -> IO ()
print :: Show a => a -> IO ()
getChar :: IO Char
getLine :: IO String
getContents :: IO String
interact :: (String -> String) -> IO ()
type FilePath = String
readFile :: FilePath -> IO String
writeFile :: FilePath -> String -> IO ()
appendFile :: FilePath -> String -> IO ()
readIO :: Read a => String -> IO a
readLn :: Read a => IO a
type IOError = IOException
ioError :: IOError -> IO a
userError :: String -> IOError
catch :: IO a -> (IOError -> IO a) -> IO a
Standard types, classes and related functions
Basic data types
(&&) :: Bool -> Bool -> BoolSource
Boolean "and"
(||) :: Bool -> Bool -> BoolSource
Boolean "or"
not :: Bool -> BoolSource
Boolean "not"
otherwise :: BoolSource

otherwise is defined as the value True. It helps to make guards more readable. eg.

  f x | x < 0     = ...

      | otherwise = ...

data Maybe a Source

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 Data.Either.Either type.

Constructors
Nothing
Just a
show/hide Instances
maybe :: b -> (a -> b) -> Maybe a -> bSource
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.
data Either a b Source

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").

Constructors
Left a
Right b
show/hide Instances
Typeable2 Either
Functor (Either a)
(Eq a, Eq b) => Eq (Either a b)
(Data a, Data b) => Data (Either a b)
(Ord a, Ord b) => Ord (Either a b)
(Read a, Read b) => Read (Either a b)
(Show a, Show b) => Show (Either a b)
either :: (a -> c) -> (b -> c) -> Either a b -> cSource
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.
type String = [Char]Source
A String is a list of characters. String constants in Haskell are values of type String.
Tuples
fst :: (a, b) -> aSource
Extract the first component of a pair.
snd :: (a, b) -> bSource
Extract the second component of a pair.
curry :: ((a, b) -> c) -> a -> b -> cSource
curry converts an uncurried function to a curried function.
uncurry :: (a -> b -> c) -> (a, b) -> cSource
uncurry converts a curried function to a function on pairs.
Basic type classes
class Eq a whereSource

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.

Minimal complete definition: either == or /=.

Methods
(==) :: a -> a -> BoolSource
(/=) :: a -> a -> BoolSource
show/hide Instances
Eq Bool
Eq Char
Eq Double
Eq Float
Eq Int
Eq Int8
Eq Int16
Eq Int32
Eq Int64
Eq Integer
Eq Ordering
Eq Word
Eq Word8
Eq Word16
Eq Word32
Eq Word64
Eq ()
Eq TyCon
Eq TypeRep
Eq ArithException
Eq Lexeme
Eq CUIntMax
Eq CIntMax
Eq CUIntPtr
Eq CIntPtr
Eq CTime
Eq CClock
Eq CSigAtomic
Eq CWchar
Eq CSize
Eq CPtrdiff
Eq CLDouble
Eq CDouble
Eq CFloat
Eq CULLong
Eq CLLong
Eq CULong
Eq CLong
Eq CUInt
Eq CInt
Eq CUShort
Eq CShort
Eq CUChar
Eq CSChar
Eq CChar
Eq IOMode
Eq IOErrorType
Eq IOException
Eq ExitCode
Eq ArrayException
Eq AsyncException
Eq BufferMode
Eq BufferState
Eq Handle
Eq GeneralCategory
Eq Inserts
Eq HashData
Eq KeyPr
Eq Key
Eq IntPtr
Eq WordPtr
Eq Errno
Eq Fd
Eq CSsize
Eq CPid
Eq COff
Eq CMode
Eq CIno
Eq CDev
Eq ConsoleEvent
Eq ThreadStatus
Eq BlockReason
Eq ThreadId
Eq FDType
Eq SeekMode
Eq HandlePosn
Eq Exception
Eq Fixity
Eq ConstrRep
Eq DataRep
Eq Constr
Eq Any
Eq All
Eq Unique
Eq Timeout
Eq Version
Eq a => Eq ([] a)
Integral a => Eq (Ratio a)
Eq (StablePtr a)
Eq (Ptr a)
Eq (FunPtr a)
Eq a => Eq ([::] a)
Eq a => Eq (Maybe a)
Eq (IORef a)
Eq (MVar a)
Eq (ForeignPtr a)
Eq (TVar a)
Eq a => Eq (Down a)
RealFloat a => Eq (Complex a)
Eq (Fixed a)
Eq a => Eq (Last a)
Eq a => Eq (First a)
Eq a => Eq (Product a)
Eq a => Eq (Sum a)
Eq a => Eq (Dual a)
Eq (StableName a)
(Eq a, Eq b) => Eq (Either a b)
(Eq a, Eq b) => Eq ((,) a b)
(Ix i, Eq e) => Eq (Array i e)
Eq (STRef s a)
Eq (IOArray i e)
(Eq a, Eq b, Eq c) => Eq ((,,) a b c)
Eq (STArray s i e)
(Eq a, Eq b, Eq c, Eq d) => Eq ((,,,) a b c d)
(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 whereSource

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.

Minimal complete definition: either compare or <=. Using compare can be more efficient for complex types.

Methods
compare :: a -> a -> OrderingSource
(<) :: a -> a -> BoolSource
(>=) :: a -> a -> BoolSource
(>) :: a -> a -> BoolSource
(<=) :: a -> a -> BoolSource
max :: a -> a -> aSource
min :: a -> a -> aSource
show/hide Instances
Ord Bool
Ord Char
Ord Double
Ord Float
Ord Int
Ord Int8
Ord Int16
Ord Int32
Ord Int64
Ord Integer
Ord Ordering
Ord Word
Ord Word8
Ord Word16
Ord Word32
Ord Word64
Ord ()
Ord ArithException
Ord CUIntMax
Ord CIntMax
Ord CUIntPtr
Ord CIntPtr
Ord CTime
Ord CClock
Ord CSigAtomic
Ord CWchar
Ord CSize
Ord CPtrdiff
Ord CLDouble
Ord CDouble
Ord CFloat
Ord CULLong
Ord CLLong
Ord CULong
Ord CLong
Ord CUInt
Ord CInt
Ord CUShort
Ord CShort
Ord CUChar
Ord CSChar
Ord CChar
Ord IOMode
Ord ExitCode
Ord ArrayException
Ord AsyncException
Ord BufferMode
Ord GeneralCategory
Ord IntPtr
Ord WordPtr
Ord Fd
Ord CSsize
Ord CPid
Ord COff
Ord CMode
Ord CIno
Ord CDev
Ord ConsoleEvent
Ord ThreadStatus
Ord BlockReason
Ord ThreadId
Ord SeekMode
Ord Any
Ord All
Ord Unique
Ord Version
Ord a => Ord ([] a)
Integral a => Ord (Ratio a)
Ord (Ptr a)
Ord (FunPtr a)
Ord a => Ord ([::] a)
Ord a => Ord (Maybe a)
Ord (ForeignPtr a)
Ord a => Ord (Down a)
Ord (Fixed a)
Ord a => Ord (Last a)
Ord a => Ord (First a)
Ord a => Ord (Product a)
Ord a => Ord (Sum a)
Ord a => Ord (Dual a)
(Ord a, Ord b) => Ord (Either a b)
(Ord a, Ord b) => Ord ((,) a b)
(Ix i, Ord e) => Ord (Array i e)
(Ord a, Ord b, Ord c) => Ord ((,,) a b c)
(Ord a, Ord b, Ord c, Ord d) => Ord ((,,,) a b c d)
(Ord a, Ord b, Ord c, Ord d, Ord e) => Ord ((,,,,) a b c d e)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f) => Ord ((,,,,,) a b c d e f)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g) => Ord ((,,,,,,) a b c d e f g)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h) => Ord ((,,,,,,,) a b c d e f g h)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i) => Ord ((,,,,,,,,) a b c d e f g h i)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j) => Ord ((,,,,,,,,,) a b c d e f g h i j)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k) => Ord ((,,,,,,,,,,) a b c d e f g h i j k)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l) => Ord ((,,,,,,,,,,,) a b c d e f g h i j k l)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m) => Ord ((,,,,,,,,,,,,) a b c d e f g h i j k l m)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n) => Ord ((,,,,,,,,,,,,,) a b c d e f g h i j k l m n)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n, Ord o) => Ord ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m n o)
class Enum a whereSource

Class Enum defines operations on sequentially ordered types.

The enumFrom... methods are used in Haskell's translation of arithmetic sequences.

Instances of Enum may be derived for any enumeration type (types whose constructors have no fields). The nullary constructors are assumed to be numbered left-to-right by fromEnum from 0 through n-1. See Chapter 10 of the Haskell Report for more details.

For any type that is an instance of class Bounded as well as Enum, the following should hold:

    enumFrom     x   = enumFromTo     x maxBound

    enumFromThen x y = enumFromThenTo x y bound

      where

        bound | fromEnum y >= fromEnum x = maxBound

              | otherwise                = minBound

Methods
succ :: a -> aSource
pred :: a -> aSource
toEnum :: Int -> aSource
fromEnum :: a -> IntSource
enumFrom :: a -> [a]Source
enumFromThen :: a -> a -> [a]Source
enumFromTo :: a -> a -> [a]Source
enumFromThenTo :: a -> a -> a -> [a]Source
show/hide Instances
class Bounded a whereSource

The Bounded class is used to name the upper and lower limits of a type. Ord is not a superclass of Bounded since types that are not totally ordered may also have upper and lower bounds.

The Bounded class may be derived for any enumeration type; minBound is the first constructor listed in the data declaration and maxBound is the last. Bounded may also be derived for single-constructor datatypes whose constituent types are in Bounded.

Methods
minBound :: aSource
maxBound :: aSource
show/hide Instances