|
| Prelude | | Portability | portable
| | Stability | stable
| | Maintainer | libraries@haskell.org
|
|
|
|
|
|
| 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 | | | | | maybe :: b -> (a -> b) -> Maybe a -> 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 | | | | class Eq a => Ord a where | | | | class Enum a where | | | | class Bounded a where | | | | type Rational = Ratio Integer | | | class (Eq a, Show a) => Num a where | | | | class (Num a, Ord a) => Real a where | | | | class (Real a, Enum a) => Integral a where | | | | class Num a => Fractional a where | | | | class Fractional a => Floating a where | | | | class (Real a, Fractional a) => RealFrac a where | | | | class (RealFrac a, Floating a) => RealFloat a where | | | | 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 | | | | 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 | | | | 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 | | | | 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
|
|
|
| Boolean "and"
|
|
|
| Boolean "or"
|
|
|
| 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 Data.Either.Either type.
| | Constructors | | Instances | |
|
|
|
| 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.
|
|
|
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 | | Instances | |
|
|
|
| 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.
|
|
|
| A String is a list of characters. String constants in Haskell are values
of type String.
|
|
| 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.
|
|
| uncurry :: (a -> b -> c) -> (a, b) -> c | Source |
|
| uncurry converts a curried function to a function on pairs.
|
|
| 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.
Minimal complete definition: either == or /=.
| | | Methods | | | 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 CUIntPtr | | Eq CIntMax | | 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 CIntPtr | | Eq CUIntMax | | Eq BufferState | | Eq BufferMode | | Eq ArrayException | | Eq ExitCode | | Eq IOMode | | Eq IOErrorType | | Eq Handle | | Eq AsyncException | | Eq IOException | | Eq GeneralCategory | | Eq HashData | | Eq Inserts | | Eq Key | | Eq KeyPr | | Eq WordPtr | | Eq IntPtr | | Eq Errno | | Eq CPid | | Eq CSsize | | Eq CDev | | Eq CIno | | Eq CMode | | Eq COff | | Eq Fd | | Eq ThreadId | | Eq BlockReason | | Eq ThreadStatus | | Eq ConsoleEvent | | Eq FDType | | Eq SeekMode | | Eq HandlePosn | | Eq Exception | | Eq DataRep | | Eq ConstrRep | | Eq Fixity | | Eq Constr | | Eq All | | Eq Any | | 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 (MVar a) | | Eq (IORef a) | | Eq (ForeignPtr a) | | Eq (TVar a) | | Eq a => Eq (Down a) | | RealFloat a => Eq (Complex a) | | Eq (Fixed a) | | Eq a => Eq (Dual a) | | Eq a => Eq (Sum a) | | Eq a => Eq (Product a) | | Eq a => Eq (First a) | | Eq a => Eq (Last 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) |
|
|
|
|
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 | | | 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 CUIntPtr | | Ord CIntMax | | Ord CChar | | Ord CSChar | | Ord CUChar | | Ord CShort | | Ord CUShort | | Ord CInt | | Ord CUInt | | Ord CLong | | Ord CULong | | Ord CLLong | | Ord CULLong | | Ord CFloat | | Ord CDouble | | Ord CLDouble | | Ord CPtrdiff | | Ord CSize | | Ord CWchar | | Ord CSigAtomic | | Ord CClock | | Ord CTime | | Ord CIntPtr | | Ord CUIntMax | | Ord BufferMode | | Ord ArrayException | | Ord ExitCode | | Ord IOMode | | Ord AsyncException | | Ord GeneralCategory | | Ord WordPtr | | Ord IntPtr | | Ord CPid | | Ord CSsize | | Ord CDev | | Ord CIno | | Ord CMode | | Ord COff | | Ord Fd | | Ord ThreadId | | Ord BlockReason | | Ord ThreadStatus | | Ord ConsoleEvent | | Ord SeekMode | | Ord All | | Ord Any | | 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 (Dual a) | | Ord a => Ord (Sum a) | | Ord a => Ord (Product a) | | Ord a => Ord (First a) | | Ord a => Ord (Last 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 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 | | | | | | | | | | | | enumFromThen :: a -> a -> [a] | Source |
| | | enumFromTo :: a -> a -> [a] | Source |
| | | enumFromThenTo :: a -> a -> a -> [a] | Source |
|
| | Instances | |
|
|
|
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 | | | Instances | | Bounded Bool | | Bounded Char | | Bounded Int | | Bounded Int8 | | Bounded Int16 | | Bounded Int32 | | Bounded Int64 | | Bounded Ordering | | Bounded Word | | Bounded Word8 | | Bounded Word16 | | Bounded Word32 | | Bounded Word64 | | Bounded () | | Bounded CUIntPtr | | Bounded CIntMax | | Bounded CChar | | Bounded CSChar | | Bounded CUChar | | Bounded CShort | | Bounded CUShort | | Bounded CInt | | Bounded CUInt | | Bounded CLong | | Bounded CULong | | Bounded CLLong | | Bounded CULLong | | Bounded CPtrdiff | | Bounded CSize | | Bounded CWchar | | Bounded CSigAtomic | | Bounded CIntPtr | | Bounded CUIntMax | | Bounded GeneralCategory | | Bounded WordPtr | | Bounded IntPtr | | Bounded CPid | | Bounded CSsize | | Bounded CIno | | Bounded CMode | | Bounded COff | | Bounded Fd | | Bounded All | | Bounded Any | | Bounded a => Bounded (Dual a) | | Bounded a => Bounded (Sum a) | | Bounded a => Bounded (Product a) | | (Bounded a, Bounded b) => Bounded ((,) a b) | | (Bounded a, Bounded b, Bounded c) => Bounded ((,,) a b c) | | (Bounded a, Bounded b, Bounded c, Bounded d) => Bounded ((,,,) a b c d) | | (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e) => Bounded ((,,,,) a b c d e) | | (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f) => Bounded ((,,,,,) a b c d e f) | | (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, |
|
|