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