[project @ 1998-08-27 13:08:54 by sof]
[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
79
80 -- These can't conveniently be defined in PrelBase because they use numbers,
81 -- or I/O, so here's a convenient place to do them.
82
83 strict      :: Eval a => (a -> b) -> a -> b
84 strict f x  = x `seq` f x
85
86
87 -- "seq" is defined a bit wierdly (see below)
88 --
89 -- The reason for the strange "0# -> parError" case is that
90 -- it fools the compiler into thinking that seq is non-strict in
91 -- its second argument (even if it inlines seq at the call site).
92 -- If it thinks seq is strict in "y", then it often evaluates
93 -- "y" before "x", which is totally wrong.  
94 --
95 -- Just before converting from Core to STG there's a bit of magic
96 -- that recognises the seq# and eliminates the duff case.
97
98 {-# INLINE seq  #-}
99 seq :: Eval a => a -> b -> b
100 seq  x y = case (seq#  x) of { 0# -> seqError; _ -> y }
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