Change a use of atomicModifyIORef to atomicModifyIORef'
[packages/base.git] / 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 #ifdef __HUGS__
41 (:), -- Not legal Haskell 98
42 #endif
43
44 -- ** Basic type classes
45 Eq((==), (/=)),
46 Ord(compare, (<), (<=), (>=), (>), max, min),
47 Enum(succ, pred, toEnum, fromEnum, enumFrom, enumFromThen,
48 enumFromTo, enumFromThenTo),
49 Bounded(minBound, maxBound),
50
51 -- ** Numbers
52
53 -- *** Numeric types
54 Int, Integer, Float, Double,
55 Rational,
56
57 -- *** Numeric type classes
58 Num((+), (-), (*), negate, abs, signum, fromInteger),
59 Real(toRational),
60 Integral(quot, rem, div, mod, quotRem, divMod, toInteger),
61 Fractional((/), recip, fromRational),
62 Floating(pi, exp, log, sqrt, (**), logBase, sin, cos, tan,
63 asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh),
64 RealFrac(properFraction, truncate, round, ceiling, floor),
65 RealFloat(floatRadix, floatDigits, floatRange, decodeFloat,
66 encodeFloat, exponent, significand, scaleFloat, isNaN,
67 isInfinite, isDenormalized, isIEEE, isNegativeZero, atan2),
68
69 -- *** Numeric functions
70 subtract, even, odd, gcd, lcm, (^), (^^),
71 fromIntegral, realToFrac,
72
73 -- ** Monads and functors
74 Monad((>>=), (>>), return, fail),
75 Functor(fmap),
76 mapM, mapM_, sequence, sequence_, (=<<),
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 #ifndef __HUGS__
142 import Control.Monad
143 import System.IO
144 import System.IO.Error
145 import Data.List
146 import Data.Either
147 import Data.Maybe
148 import Data.Tuple
149 #endif
150
151 #ifdef __GLASGOW_HASKELL__
152 import GHC.Base
153 import Text.Read
154 import GHC.Enum
155 import GHC.Num
156 import GHC.Real
157 import GHC.Float
158 import GHC.Show
159 #endif
160
161 #ifdef __HUGS__
162 import Hugs.Prelude
163 #endif
164
165 #ifndef __HUGS__
166 infixr 0 $!
167 #endif
168
169 -- -----------------------------------------------------------------------------
170 -- Miscellaneous functions
171
172 -- | Strict (call-by-value) application, defined in terms of 'seq'.
173 ($!) :: (a -> b) -> a -> b
174 #ifdef __GLASGOW_HASKELL__
175 f $! x = let !vx = x in f vx -- see #2273
176 #elif !defined(__HUGS__)
177 f $! x = x `seq` f x
178 #endif
179
180 #ifdef __HADDOCK__
181 -- | The value of @'seq' a b@ is bottom if @a@ is bottom, and otherwise
182 -- equal to @b@. 'seq' is usually introduced to improve performance by
183 -- avoiding unneeded laziness.
184 seq :: a -> b -> b
185 seq _ y = y
186 #endif