Haskell Hierarchical Libraries (base package)ContentsIndex
Prelude
Portability portable
Stability stable
Maintainer libraries@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
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
data Bool
= False
| True
(&&) :: 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
data Ordering
= LT
| EQ
| GT
data Char
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
data Int
data Integer
data Float
data Double
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
log :: a -> a
sqrt :: a -> a
(**) :: a -> a -> a
logBase :: a -> a -> a
sin :: a -> a
cos :: a -> a
tan :: a -> a
asin :: a -> a
acos :: a -> a
atan :: a -> a
sinh :: a -> a
cosh :: a -> a
tanh :: a -> a
asinh :: a -> a
acosh :: a -> a
atanh :: 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
even :: Integral a => a -> Bool
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
(>>=) :: m a -> (a -> m b) -> m 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 :: String -> 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 ReadS a = String -> [(a, String)]
type ShowS = String -> String
class Read a where
readsPrec :: Int -> ReadS a
readList :: ReadS [a]
class Show a where
showsPrec :: Int -> a -> ShowS
show :: a -> String
showList :: [a] -> ShowS
reads :: Read a => ReadS a
shows :: Show a => a -> ShowS
read :: Read a => String -> a
lex :: ReadS String
showChar :: Char -> ShowS
showString :: String -> ShowS
readParen :: Bool -> ReadS a -> ReadS a
showParen :: Bool -> ShowS -> ShowS
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
data Bool
The Bool type is an enumeration. It is defined with False first so that the corresponding Enum instance will give fromEnum False the value zero, and fromEnum True the value 1.
Constructors
False
True
Instances
IArray UArray Bool
Ix ix => Eq (UArray ix Bool)
Ix ix => Ord (UArray ix Bool)
(Ix ix, Show ix) => Show (UArray ix Bool)
MArray (STUArray s) Bool (ST s)
MArray IOUArray Bool IO
Typeable Bool
Storable Bool
Ix Bool
Eq Bool
Ord Bool
Bounded Bool
Enum Bool
Read Bool
Show Bool
Random Bool
(&&) :: Bool -> Bool -> Bool
Boolean "and"
(||) :: Bool -> Bool -> Bool
Boolean "or"
not :: Bool -> Bool
Boolean "not"
otherwise :: Bool

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

  f x | x < 0     = ...
      | otherwise = ...
data Maybe a

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.

Constructors
Nothing
Just a
Instances
MonadPlus Maybe
MonadFix Maybe
Data a => Data (Maybe a)
Functor Maybe
Monad Maybe
Eq a => Eq (Maybe a)
Ord a => Ord (Maybe a)
Typeable a => Typeable (Maybe a)
Read a => Read (Maybe a)
Show a => Show (Maybe a)
maybe :: b -> (a -> b) -> Maybe a -> b
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 that.
data Either a b

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
Instances
Functor (Either e)
Error e => Monad (Either e)
Error e => MonadPlus (Either e)
Error e => MonadFix (Either e)
Error e => MonadError e (Either e)
(Eq a, Eq b) => Eq (Either a b)
(Ord a, Ord b) => Ord (Either a b)
(Typeable a, Typeable b) => Typeable (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 -> c
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.
data Ordering
Represents an ordering relationship between two values: less than, equal to, or greater than. An Ordering is returned by compare.
Constructors
LT
EQ
GT
Instances
Typeable Ordering
Ix Ordering
Eq Ordering
Ord Ordering
Bounded Ordering
Enum Ordering
Read Ordering
Show Ordering
data Char

The character type Char is an enumeration whose values represent Unicode (or equivalently ISO 10646) characters. This set extends the ISO 8859-1 (Latin-1) character set (the first 256 charachers), 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
Error [Char]
IArray UArray Char
Ix ix => Eq (UArray ix Char)
Ix ix => Ord (UArray ix Char)
(Ix ix, Show ix) => Show (UArray ix Char)
MArray (STUArray s) Char (ST s)
(Ix ix, Show ix) => Show (DiffUArray ix Char)
IArray (IOToDiffArray IOUArray) Char
MArray IOUArray Char IO
Typeable Char
Storable Char
Ix Char
Eq Char
Ord Char
Bounded Char
Enum Char
Read Char
Show Char
Random Char
HTML Char
type String = [Char]
A String is a list of characters. String constants in Haskell are values of type String.
Tuples
fst :: (a, b) -> a
snd :: (a, b) -> b
curry :: ((a, b) -> c) -> a -> b -> c
uncurry :: (a -> b -> c) -> (a, b) -> c
Basic type classes
class Eq a where

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 -> Bool
(/=) :: a -> a -> Bool
Instances
Eq ThreadId
Ix ix => Eq (UArray ix Bool)
Ix ix => Eq (UArray ix Char)
Ix ix => Eq (UArray ix Int)
Ix ix => Eq (UArray ix Word)
Ix ix => Eq (UArray ix (Ptr a))
Ix ix => Eq (UArray ix (FunPtr a))
Ix ix => Eq (UArray ix Float)
Ix ix => Eq (UArray ix Double)
Ix ix => Eq (UArray ix (StablePtr a))
Ix ix => Eq (UArray ix Int8)
Ix ix => Eq (UArray ix Int16)
Ix ix => Eq (UArray ix Int32)
Ix ix => Eq (UArray ix Int64)
Ix ix => Eq (UArray ix Word8)
Ix ix => Eq (UArray ix Word16)
Ix ix => Eq (UArray ix Word32)
Ix ix => Eq (UArray ix Word64)
(RealFloat a, Eq a) => Eq (Complex a)
(Eq a, Eq b) => Eq (Either a b)
(Eq key, Eq elt) => Eq (FiniteMap key elt)
Eq a => Eq (Maybe a)
Eq PackedString
Eq a => Eq (Set a)
(Eq a, Eq b) => Eq (a, b)
(Eq a, Eq b, Eq c) => Eq (a, b, c)
(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)
Eq TypeRep
Eq TyCon
Eq Key
Eq KeyPr
Eq Unique
Eq Errno
Eq CChar
Eq CSChar
Eq CUChar
Eq CShort
Eq CUShort
Eq CInt
Eq CUInt
Eq CLong
Eq CULong
Eq CLLong
Eq CULLong
Eq CFloat
Eq CDouble
Eq CLDouble
Eq CPtrdiff
Eq CSize
Eq CWchar
Eq CSigAtomic
Eq CClock
Eq CTime
Eq (STArray s i e)
(Ix i, Eq e) => Eq (Array i e)
Eq a => Eq [a]
Eq ()
Eq Char
Eq Int
Eq Bool
Eq Ordering
Eq Float
Eq Double
Eq (ForeignPtr a)
Eq HandlePosn
Eq SeekMode
Eq (MVar a)
Eq Handle
Eq (IORef a)
Eq (IOArray i e)
Eq Exception
Eq IOException
Eq IOErrorType
Eq BufferState
Eq BufferMode
Eq ArithException
Eq AsyncException
Eq ArrayException
Eq ExitCode
Eq IOMode
Eq Int64
Eq Int8
Eq Int16
Eq Int32
Eq Integer
Eq (Ptr a)
Eq (FunPtr a)
(Integral a, Eq a) => Eq (Ratio a)
Eq (STRef s a)
Eq (StablePtr a)
Eq Word64
Eq Word
Eq Word8
Eq Word16
Eq Word32
Eq Permissions
Eq TimeLocale
Eq (StableName a)
Eq FDType
Eq CDev
Eq CIno
Eq CMode
Eq COff
Eq CPid
Eq CSsize
Eq CGid
Eq CNlink
Eq CUid
Eq CCc
Eq CSpeed
Eq CTcflag
Eq Fd
Eq Month
Eq Day
Eq ClockTime
Eq CalendarTime
Eq TimeDiff
Eq Lexeme
class Eq a => Ord a where
Methods
compare :: a -> a -> Ordering
(<) :: a -> a -> Bool
(<=) :: a -> a -> Bool
(>) :: a -> a -> Bool
(>=) :: a -> a -> Bool
max :: a -> a -> a
min :: a -> a -> a
Instances
Ord ThreadId
Ix ix => Ord (UArray ix Bool)
Ix ix => Ord (UArray ix Char)
Ix ix => Ord (UArray ix Int)
Ix ix => Ord (UArray ix Word)
Ix ix => Ord (UArray ix (Ptr a))
Ix ix => Ord (UArray ix (FunPtr a))
Ix ix => Ord (UArray ix Float)
Ix ix => Ord (UArray ix Double)
Ix ix => Ord (UArray ix Int8)
Ix ix => Ord (UArray ix Int16)
Ix ix => Ord (UArray ix Int32)
Ix ix => Ord (UArray ix Int64)
Ix ix => Ord (UArray ix Word8)
Ix ix => Ord (UArray ix Wor