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