IsString is GHC-only (so why is it in the Prelude?)
[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 #ifdef __GLASGOW_HASKELL__
84 -- ** String class
85 IsString(fromString),
86 #endif
87
88 -- ** Miscellaneous functions
89 id, const, (.), flip, ($), until,
90 asTypeOf, error, undefined,
91 seq, ($!),
92
93 -- * List operations
94 map, (++), filter,
95 head, last, tail, init, null, length, (!!),
96 reverse,
97 -- ** Reducing lists (folds)
98 foldl, foldl1, foldr, foldr1,
99 -- *** Special folds
100 and, or, any, all,
101 sum, product,
102 concat, concatMap,
103 maximum, minimum,
104 -- ** Building lists
105 -- *** Scans
106 scanl, scanl1, scanr, scanr1,
107 -- *** Infinite lists
108 iterate, repeat, replicate, cycle,
109 -- ** Sublists
110 take, drop, splitAt, takeWhile, dropWhile, span, break,
111 -- ** Searching lists
112 elem, notElem, lookup,
113 -- ** Zipping and unzipping lists
114 zip, zip3, zipWith, zipWith3, unzip, unzip3,
115 -- ** Functions on strings
116 lines, words, unlines, unwords,
117
118 -- * Converting to and from @String@
119 -- ** Converting to @String@
120 ShowS,
121 Show(showsPrec, showList, show),
122 shows,
123 showChar, showString, showParen,
124 -- ** Converting from @String@
125 ReadS,
126 Read(readsPrec, readList),
127 reads, readParen, read, lex,
128
129 -- * Basic Input and output
130 IO,
131 -- ** Simple I\/O operations
132 -- All I/O functions defined here are character oriented. The
133 -- treatment of the newline character will vary on different systems.
134 -- For example, two characters of input, return and linefeed, may
135 -- read as a single newline character. These functions cannot be
136 -- used portably for binary I/O.
137 -- *** Output functions
138 putChar,
139 putStr, putStrLn, print,
140 -- *** Input functions
141 getChar,
142 getLine, getContents, interact,
143 -- *** Files
144 FilePath,
145 readFile, writeFile, appendFile, readIO, readLn,
146 -- ** Exception handling in the I\/O monad
147 IOError, ioError, userError, catch
148
149 ) where
150
151 #ifndef __HUGS__
152 import Control.Monad
153 import System.IO
154 import Text.Read
155 import Text.Show
156 import Data.List
157 import Data.Either
158 import Data.Maybe
159 import Data.Bool
160 import Data.Tuple
161 import Data.Eq
162 import Data.Ord
163 #endif
164
165 #ifdef __GLASGOW_HASKELL__
166 import GHC.Base
167 import GHC.IOBase
168 import GHC.Exception
169 import GHC.Read
170 import GHC.Enum
171 import GHC.Num
172 import GHC.Real
173 import GHC.Float
174 import GHC.Show
175 import GHC.Err ( error, undefined )
176 #endif
177
178 #ifdef __HUGS__
179 import Hugs.Prelude
180 #endif
181
182 #ifndef __HUGS__
183 infixr 0 $!
184
185 -- -----------------------------------------------------------------------------
186 -- Miscellaneous functions
187
188 -- | Strict (call-by-value) application, defined in terms of 'seq'.
189 ($!) :: (a -> b) -> a -> b
190 f $! x = x `seq` f x
191 #endif
192
193 #ifdef __HADDOCK__
194 -- | The value of @'seq' a b@ is bottom if @a@ is bottom, and otherwise
195 -- equal to @b@. 'seq' is usually introduced to improve performance by
196 -- avoiding unneeded laziness.
197 seq :: a -> b -> b
198 seq _ y = y
199 #endif