0b9f102379cff8dfeccbc962d3f9162f5634463c
[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 corresponding to the Report's PreludeList
11     module PrelList, 
12     lines, words, unlines, unwords,
13     sum, product,
14
15         -- Everything corresponding to the Report's PreludeText
16     ReadS, ShowS,
17     Read(readsPrec, readList),
18     Show(showsPrec, showList, show),
19     reads, shows, read, lex, 
20     showChar, showString, readParen, showParen,
21     
22         -- Everything corresponding to the Report's PreludeIO
23     FilePath, IOError,
24     ioError, userError, catch,
25     putChar, putStr, putStrLn, print,
26     getChar, getLine, getContents, interact,
27     readFile, writeFile, appendFile, readIO, readLn,
28
29     Bool(..),
30     Maybe(..),
31     Either(..),
32     Ordering(..), 
33     Char, String, Int, Integer, Float, Double, IO,
34     Rational,
35     []((:), []),
36     
37     module PrelTup,
38         -- Includes tuple types + fst, snd, curry, uncurry
39     ()(..),             -- The unit type
40     (->),               -- functions
41     
42     Eq(..),
43     Ord(..), 
44     Enum(..),
45     Bounded(..), 
46     Num((+), (-), (*), negate, abs, signum, fromInteger),
47         -- The fromInt method is exposed only by GlaExts
48     Real(..),
49     Integral(quot, rem, div, mod, quotRem, divMod, toInteger),
50         -- The toInt method is exposed only by GlaExts
51     Fractional(..),
52     Floating(..),
53     RealFrac(..),
54     RealFloat(..),
55
56         -- From Monad
57     Monad(..),
58     Functor(..), 
59     mapM, mapM_, sequence, sequence_, (=<<),
60
61     maybe, either,
62     (&&), (||), not, otherwise,
63     subtract, even, odd, gcd, lcm, (^), (^^), 
64     fromIntegral, realToFrac,
65     --exported by PrelTup: fst, snd, curry, uncurry,
66     id, const, (.), flip, ($), until,
67     asTypeOf, error, undefined,
68     seq, ($!)
69
70   ) where
71
72 import PrelBase
73 import PrelList
74 #ifndef USE_REPORT_PRELUDE
75      hiding ( takeUInt_append )
76 #endif
77 import PrelRead
78 import PrelEnum
79 import PrelNum
80 import PrelNumExtra
81 import PrelTup
82 import PrelMaybe
83 import PrelShow
84 import PrelConc
85 import Monad
86 import Maybe
87 import PrelErr   ( error )
88 import IO
89
90 infixr 0 $!
91
92 ($!)    :: (a -> b) -> a -> b
93 f $! x  = x `seq` f x
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 List sum and product are defined here because PrelList is too far
105 down the compilation chain to "see" the Num class.
106
107 \begin{code}
108 -- sum and product compute the sum or product of a finite list of numbers.
109 {-# SPECIALISE sum     :: [Int] -> Int #-}
110 {-# SPECIALISE sum     :: [Integer] -> Integer #-}
111 {-# SPECIALISE product :: [Int] -> Int #-}
112 {-# SPECIALISE product :: [Integer] -> Integer #-}
113 sum, product            :: (Num a) => [a] -> a
114 #ifdef USE_REPORT_PRELUDE
115 sum                     =  foldl (+) 0  
116 product                 =  foldl (*) 1
117 #else
118 sum     l       = sum' l 0
119   where
120     sum' []     a = a
121     sum' (x:xs) a = sum' xs (a+x)
122 product l       = prod l 1
123   where
124     prod []     a = a
125     prod (x:xs) a = prod xs (a*x)
126 #endif
127 \end{code}