[project @ 1997-10-08 12:53:37 by simonm]
[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 IOBase
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 Monad
71 import Maybe
72 import IOBase   ( error )
73 import GHCerr
74
75 -- These can't conveniently be defined in PrelBase because they use numbers,
76 -- or I/O, so here's a convenient place to do them.
77
78 strict      :: Eval a => (a -> b) -> a -> b
79 strict f x  = x `seq` f x
80
81
82 -- "seq" is defined a bit wierdly (see below)
83 --
84 -- The reason for the strange "0# -> parError" case is that
85 -- it fools the compiler into thinking that seq is non-strict in
86 -- its second argument (even if it inlines seq at the call site).
87 -- If it thinks seq is strict in "y", then it often evaluates
88 -- "y" before "x", which is totally wrong.  
89 --
90 -- Just before converting from Core to STG there's a bit of magic
91 -- that recognises the seq# and eliminates the duff case.
92
93 {-# INLINE seq  #-}
94 seq :: Eval a => a -> b -> b
95 seq  x y = case (seq#  x) of { 0# -> seqError; _ -> y }
96
97 seqError :: a
98 seqError = error "Oops! Entered seqError (a GHC bug -- please report it!)\n"
99
100 -- It is expected that compilers will recognize this and insert error
101 -- messages which are more appropriate to the context in which undefined 
102 -- appears. 
103
104 undefined               :: a
105 undefined               =  error "Prelude.undefined"
106 \end{code}
107
108
109