92d173f321213f532b17b267dd0b621df764dffd
[ghc-hetmet.git] / ghc / lib / required / 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 PrelIO,
13     module PrelTup,
14
15         -- From PrelBase
16     (->),
17     Eq(..), 
18     Ord(..), Ordering(..), 
19     Bounded(..), 
20     Enum(..), succ, pred, 
21     Show(..), ShowS, shows, show, showChar, showString, showParen,
22     Num(..), 
23     Eval(..), seq, strict,
24     Bool(..), (&&), (||), not, otherwise,
25     Char, String, Int, Integer, Float, Double, Void,
26     Maybe(..), maybe,
27     Either(..), either,
28     ()(..),             -- The unit type
29
30     
31     id, const, (.), flip, ($), until, asTypeOf, undefined,
32
33         -- From Error
34     error,
35
36         -- From Monad
37     Functor(..), Monad(..), MonadZero(..), MonadPlus(..),
38     accumulate, sequence, mapM, mapM_, guard, filter, concat, applyM,
39
40         -- From PrelRead
41     ReadS, Read(readsPrec, readList),
42     reads, read, lex, readParen, 
43
44         -- From PrelShow
45
46         -- From PrelNum
47     Ratio, Rational, 
48     (%), numerator, denominator, approxRational,
49
50     Num((+), (-), (*), negate, abs, signum, fromInteger),
51     Real(toRational),
52     Integral(quot, rem, div, mod, quotRem, divMod, toInteger, toInt{-partain-}),
53     Fractional((/), recip, fromRational),
54     Floating(pi, exp, log, sqrt, (**), logBase, sin, cos, tan,
55              asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh),
56     RealFrac(properFraction, truncate, round, ceiling, floor),
57     RealFloat(floatRadix, floatDigits, floatRange, decodeFloat,
58               encodeFloat, exponent, significand, scaleFloat, isNaN,
59               isInfinite, isDenormalized, isIEEE, isNegativeZero),
60     subtract, even, odd, gcd, lcm, (^), (^^), 
61     fromIntegral, fromRealFrac, atan2
62   ) where
63
64 import PrelBase
65 import PrelList
66 import PrelIO
67 import PrelRead
68 import PrelNum
69 import PrelTup
70 import PrelMaybe
71 import PrelEither
72 import Monad
73 import Maybe
74 import Error    ( error )
75 import GHCerr
76
77 -- These can't conveniently be defined in PrelBase because they use numbers,
78 -- or I/O, so here's a convenient place to do them.
79
80 strict      :: Eval a => (a -> b) -> a -> b
81 strict f x  = x `seq` f x
82
83
84 -- "seq" is defined a bit wierdly (see below)
85 --
86 -- The reason for the strange "0# -> parError" case is that
87 -- it fools the compiler into thinking that seq is non-strict in
88 -- its second argument (even if it inlines seq at the call site).
89 -- If it thinks seq is strict in "y", then it often evaluates
90 -- "y" before "x", which is totally wrong.  
91 --
92 -- Just before converting from Core to STG there's a bit of magic
93 -- that recognises the seq# and eliminates the duff case.
94
95 {-# INLINE seq  #-}
96 seq :: Eval a => a -> b -> b
97 seq  x y = case (seq#  x) of { 0# -> seqError; _ -> y }
98
99 seqError :: a
100 seqError = error "Oops! Entered seqError (a GHC bug -- please report it!)\n"
101
102 -- It is expected that compilers will recognize this and insert error
103 -- messages which are more appropriate to the context in which undefined 
104 -- appears. 
105
106 undefined               :: a
107 undefined               =  error "Prelude.undefined"
108 \end{code}
109
110
111