1ba96bb4ad4a5b33bff13a3128e1d49a11ea37d1
[ghc-hetmet.git] / ghc / lib / std / Prelude.lhs
1 We add the option -fno-implicit-prelude here to tell the reader that
2 special names such as () and -> shouldn't be resolved to Prelude.()
3 and Prelude.-> (as they are normally). -- SDM 8/10/97
4
5 \begin{code}
6 {-# OPTIONS -fno-implicit-prelude #-}
7
8 module Prelude (
9
10         -- Everything from these modules
11     module PrelList,
12     module PrelTup,
13
14         -- From PrelBase
15     (->),
16     Eq(..), 
17     Ord(..), Ordering(..), 
18     Bounded(..), 
19     Enum(..), succ, pred, 
20     Show(..), ShowS, shows, show, showChar, showString, showParen,
21     Eval(..), seq, strict,
22     Bool(..), (&&), (||), not, otherwise,
23     Char, String, Int, Integer, Float, Double, Void,
24     Maybe(..), maybe,
25     Either(..), either,
26     ()(..),             -- The unit type
27
28     
29     id, const, (.), flip, ($), until, asTypeOf, undefined,
30
31         -- From Error
32     error,
33
34         -- From Monad
35     Functor(..), Monad(..), MonadZero(..), MonadPlus(..),
36     accumulate, sequence, mapM, mapM_, guard, filter, concat, applyM,
37
38         -- From PrelRead
39     ReadS, Read(readsPrec, readList),
40     reads, read, lex, readParen, 
41
42         -- From IO
43     IO, FilePath, IOError,
44     fail, userError, catch,
45     putChar, putStr, putStrLn, print,
46     getChar, getLine, getContents, interact,
47     readFile, writeFile, appendFile, readIO, readLn,
48
49         -- From PrelNum
50     Ratio, Rational, 
51     (%), numerator, denominator, approxRational,
52
53     Num((+), (-), (*), negate, abs, signum, fromInteger, fromInt{-glaExt-}),
54     Real(toRational),
55     Integral(quot, rem, div, mod, quotRem, divMod, toInteger, toInt{-partain-}),
56     Fractional((/), recip, fromRational),
57     Floating(pi, exp, log, sqrt, (**), logBase, sin, cos, tan,
58              asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh),
59     RealFrac(properFraction, truncate, round, ceiling, floor),
60     RealFloat(floatRadix, floatDigits, floatRange, decodeFloat,
61               encodeFloat, exponent, significand, scaleFloat, isNaN,
62               isInfinite, isDenormalized, isIEEE, isNegativeZero),
63     subtract, even, odd, gcd, lcm, (^), (^^), 
64     fromIntegral, fromRealFrac, atan2
65   ) where
66
67 import PrelBase
68 import PrelList
69 import PrelRead
70 import PrelNum
71 import PrelTup
72 import PrelMaybe
73 import PrelEither
74 import PrelBounded
75 import Monad
76 import Maybe
77 import PrelErr   ( error, seqError )
78 import IO  ( IO, FilePath, IOError,
79              fail, userError, catch,
80              putChar, putStr, putStrLn, print,
81              getChar, getLine, getContents, interact,
82              readFile, writeFile, appendFile, readIO, readLn
83            )
84
85 {- Declared elsewhere:
86 PrelBase: infixr 9 .
87 PrelNum:  infixr 8 ^, ^^, **
88 PrelBase: infixl *
89 PrelNum:  infixl 7 /, %, `quot`, `rem`, `div`, `mod`
90 PrelBase: infixl 6 +, -
91 PrelBase: infixr 5 :, ++
92 PrelBase: infix  4 ==, /=, <. <=, >=, >
93 PrelBase: infixr 3 &&
94 PrelBase: infixr 2 ||
95 PrelBase: infixl >>, >>=
96 PrelBase: infixr $
97 -}
98 infixr 0 `seq`
99
100
101 -- These can't conveniently be defined in PrelBase because they use numbers,
102 -- or I/O, so here's a convenient place to do them.
103
104 strict      :: Eval a => (a -> b) -> a -> b
105 strict f x  = x `seq` f x
106
107
108 -- "seq" is defined a bit wierdly (see below)
109 --
110 -- The reason for the strange "0# -> parError" case is that
111 -- it fools the compiler into thinking that seq is non-strict in
112 -- its second argument (even if it inlines seq at the call site).
113 -- If it thinks seq is strict in "y", then it often evaluates
114 -- "y" before "x", which is totally wrong.  
115 --
116 -- Just before converting from Core to STG there's a bit of magic
117 -- that recognises the seq# and eliminates the duff case.
118
119 {-# INLINE seq  #-}
120 seq :: Eval a => a -> b -> b
121 seq  x y = case (seq#  x) of { 0# -> seqError; _ -> y }
122
123 -- It is expected that compilers will recognize this and insert error
124 -- messages which are more appropriate to the context in which undefined 
125 -- appears. 
126
127 undefined               :: a
128 undefined               =  error "Prelude.undefined"
129 \end{code}
130
131
132