854456a3dbaf2cdf466b5a1e463026fc4adad0de
[ghc.git] / libraries / base / Prelude.hs
1 {-# LANGUAGE Trustworthy #-}
2 {-# LANGUAGE CPP, NoImplicitPrelude, BangPatterns #-}
3
4 -----------------------------------------------------------------------------
5 -- |
6 -- Module : Prelude
7 -- Copyright : (c) The University of Glasgow 2001
8 -- License : BSD-style (see the file libraries/base/LICENSE)
9 --
10 -- Maintainer : libraries@haskell.org
11 -- Stability : stable
12 -- Portability : portable
13 --
14 -- The Prelude: a standard module. The Prelude is imported by default
15 -- into all Haskell modules unless either there is an explicit import
16 -- statement for it, or the NoImplicitPrelude extension is enabled.
17 --
18 -----------------------------------------------------------------------------
19
20 module Prelude (
21
22 -- * Standard types, classes and related functions
23
24 -- ** Basic data types
25 Bool(False, True),
26 (&&), (||), not, otherwise,
27
28 Maybe(Nothing, Just),
29 maybe,
30
31 Either(Left, Right),
32 either,
33
34 Ordering(LT, EQ, GT),
35 Char, String,
36
37 -- *** Tuples
38 fst, snd, curry, uncurry,
39
40 -- ** Basic type classes
41 Eq((==), (/=)),
42 Ord(compare, (<), (<=), (>=), (>), max, min),
43 Enum(succ, pred, toEnum, fromEnum, enumFrom, enumFromThen,
44 enumFromTo, enumFromThenTo),
45 Bounded(minBound, maxBound),
46
47 -- ** Numbers
48
49 -- *** Numeric types
50 Int, Integer, Float, Double,
51 Rational, Word,
52
53 -- *** Numeric type classes
54 Num((+), (-), (*), negate, abs, signum, fromInteger),
55 Real(toRational),
56 Integral(quot, rem, div, mod, quotRem, divMod, toInteger),
57 Fractional((/), recip, fromRational),
58 Floating(pi, exp, log, sqrt, (**), logBase, sin, cos, tan,
59 asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh),
60 RealFrac(properFraction, truncate, round, ceiling, floor),
61 RealFloat(floatRadix, floatDigits, floatRange, decodeFloat,
62 encodeFloat, exponent, significand, scaleFloat, isNaN,
63 isInfinite, isDenormalized, isIEEE, isNegativeZero, atan2),
64
65 -- *** Numeric functions
66 subtract, even, odd, gcd, lcm, (^), (^^),
67 fromIntegral, realToFrac,
68
69 -- ** Monads and functors
70 Functor(fmap),
71 Applicative(pure, (<*>), (*>), (<*)),
72 Monad((>>=), (>>), return, fail),
73 mapM, mapM_, sequence, sequence_, (=<<),
74
75 -- ** Traversals and Foldables
76 Foldable, Traversable,
77
78 -- ** Miscellaneous functions
79 id, const, (.), flip, ($), until,
80 asTypeOf, error, undefined,
81 seq, ($!),
82
83 -- * List operations
84 map, (++), filter,
85 head, last, tail, init, null, length, (!!),
86 reverse,
87 -- ** Reducing lists (folds)
88 foldl, foldl1, foldr, foldr1,
89 -- *** Special folds
90 and, or, any, all,
91 sum, product,
92 concat, concatMap,
93 maximum, minimum,
94 -- ** Building lists
95 -- *** Scans
96 scanl, scanl1, scanr, scanr1,
97 -- *** Infinite lists
98 iterate, repeat, replicate, cycle,
99 -- ** Sublists
100 take, drop, splitAt, takeWhile, dropWhile, span, break,
101 -- ** Searching lists
102 elem, notElem, lookup,
103 -- ** Zipping and unzipping lists
104 zip, zip3, zipWith, zipWith3, unzip, unzip3,
105 -- ** Functions on strings
106 lines, words, unlines, unwords,
107
108 -- * Converting to and from @String@
109 -- ** Converting to @String@
110 ShowS,
111 Show(showsPrec, showList, show),
112 shows,
113 showChar, showString, showParen,
114 -- ** Converting from @String@
115 ReadS,
116 Read(readsPrec, readList),
117 reads, readParen, read, lex,
118
119 -- * Basic Input and output
120 IO,
121 -- ** Simple I\/O operations
122 -- All I/O functions defined here are character oriented. The
123 -- treatment of the newline character will vary on different systems.
124 -- For example, two characters of input, return and linefeed, may
125 -- read as a single newline character. These functions cannot be
126 -- used portably for binary I/O.
127 -- *** Output functions
128 putChar,
129 putStr, putStrLn, print,
130 -- *** Input functions
131 getChar,
132 getLine, getContents, interact,
133 -- *** Files
134 FilePath,
135 readFile, writeFile, appendFile, readIO, readLn,
136 -- ** Exception handling in the I\/O monad
137 IOError, ioError, userError,
138
139 ) where
140
141 import Control.Monad
142 import System.IO
143 import System.IO.Error
144 import Data.List
145 import Data.Either
146 import Data.Foldable ( Foldable )
147 import Data.Maybe
148 import Data.Traversable ( Traversable )
149 import Data.Tuple
150
151 import GHC.Base hiding ( foldr, mapM, sequence )
152 import Text.Read
153 import GHC.Enum
154 import GHC.Num
155 import GHC.Real
156 import GHC.Float
157 import GHC.Show