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