Merge branch 'master' of darcs.haskell.org:/srv/darcs//packages/base
[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 imported by default into all Haskell
15 -- modules. For more documentation, see the Haskell 98 Report
16 -- <http://www.haskell.org/onlinereport/>.
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 #if defined(__NHC__)
41 []((:), []), -- Not legal Haskell 98;
42 -- ... available through built-in syntax
43 module Data.Tuple, -- Includes tuple types
44 ()(..), -- Not legal Haskell 98
45 (->), -- ... available through built-in syntax
46 #endif
47 #ifdef __HUGS__
48 (:), -- Not legal Haskell 98
49 #endif
50
51 -- ** Basic type classes
52 Eq((==), (/=)),
53 Ord(compare, (<), (<=), (>=), (>), max, min),
54 Enum(succ, pred, toEnum, fromEnum, enumFrom, enumFromThen,
55 enumFromTo, enumFromThenTo),
56 Bounded(minBound, maxBound),
57
58 -- ** Numbers
59
60 -- *** Numeric types
61 Int, Integer, Float, Double,
62 Rational,
63
64 -- *** Numeric type classes
65 Num((+), (-), (*), negate, abs, signum, fromInteger),
66 Real(toRational),
67 Integral(quot, rem, div, mod, quotRem, divMod, toInteger),
68 Fractional((/), recip, fromRational),
69 Floating(pi, exp, log, sqrt, (**), logBase, sin, cos, tan,
70 asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh),
71 RealFrac(properFraction, truncate, round, ceiling, floor),
72 RealFloat(floatRadix, floatDigits, floatRange, decodeFloat,
73 encodeFloat, exponent, significand, scaleFloat, isNaN,
74 isInfinite, isDenormalized, isIEEE, isNegativeZero, atan2),
75
76 -- *** Numeric functions
77 subtract, even, odd, gcd, lcm, (^), (^^),
78 fromIntegral, realToFrac,
79
80 -- ** Monads and functors
81 Monad((>>=), (>>), return, fail),
82 Functor(fmap),
83 mapM, mapM_, sequence, sequence_, (=<<),
84
85 -- ** Miscellaneous functions
86 id, const, (.), flip, ($), until,
87 asTypeOf, error, undefined,
88 seq, ($!),
89
90 -- * List operations
91 map, (++), filter,
92 head, last, tail, init, null, length, (!!),
93 reverse,
94 -- ** Reducing lists (folds)
95 foldl, foldl1, foldr, foldr1,
96 -- *** Special folds
97 and, or, any, all,
98 sum, product,
99 concat, concatMap,
100 maximum, minimum,
101 -- ** Building lists
102 -- *** Scans
103 scanl, scanl1, scanr, scanr1,
104 -- *** Infinite lists
105 iterate, repeat, replicate, cycle,
106 -- ** Sublists
107 take, drop, splitAt, takeWhile, dropWhile, span, break,
108 -- ** Searching lists
109 elem, notElem, lookup,
110 -- ** Zipping and unzipping lists
111 zip, zip3, zipWith, zipWith3, unzip, unzip3,
112 -- ** Functions on strings
113 lines, words, unlines, unwords,
114
115 -- * Converting to and from @String@
116 -- ** Converting to @String@
117 ShowS,
118 Show(showsPrec, showList, show),
119 shows,
120 showChar, showString, showParen,
121 -- ** Converting from @String@
122 ReadS,
123 Read(readsPrec, readList),
124 reads, readParen, read, lex,
125
126 -- * Basic Input and output
127 IO,
128 -- ** Simple I\/O operations
129 -- All I/O functions defined here are character oriented. The
130 -- treatment of the newline character will vary on different systems.
131 -- For example, two characters of input, return and linefeed, may
132 -- read as a single newline character. These functions cannot be
133 -- used portably for binary I/O.
134 -- *** Output functions
135 putChar,
136 putStr, putStrLn, print,
137 -- *** Input functions
138 getChar,
139 getLine, getContents, interact,
140 -- *** Files
141 FilePath,
142 readFile, writeFile, appendFile, readIO, readLn,
143 -- ** Exception handling in the I\/O monad
144 IOError, ioError, userError,
145
146 ) where
147
148 #ifndef __HUGS__
149 import Control.Monad
150 import System.IO
151 import System.IO.Error
152 import Data.List
153 import Data.Either
154 import Data.Maybe
155 import Data.Tuple
156 #endif
157
158 #ifdef __GLASGOW_HASKELL__
159 import GHC.Base
160 import Text.Read
161 import GHC.Enum
162 import GHC.Num
163 import GHC.Real
164 import GHC.Float
165 import GHC.Show
166 import GHC.Err ( undefined )
167 #endif
168
169 #ifdef __HUGS__
170 import Hugs.Prelude
171 #endif
172
173 #ifndef __HUGS__
174 infixr 0 $!
175 #endif
176
177 -- -----------------------------------------------------------------------------
178 -- Miscellaneous functions
179
180 -- | Strict (call-by-value) application, defined in terms of 'seq'.
181 ($!) :: (a -> b) -> a -> b
182 #ifdef __GLASGOW_HASKELL__
183 f $! x = let !vx = x in f vx -- see #2273
184 #elif !defined(__HUGS__)
185 f $! x = x `seq` f x
186 #endif
187
188 #ifdef __HADDOCK__
189 -- | The value of @'seq' a b@ is bottom if @a@ is bottom, and otherwise
190 -- equal to @b@. 'seq' is usually introduced to improve performance by
191 -- avoiding unneeded laziness.
192 seq :: a -> b -> b
193 seq _ y = y
194 #endif