[project @ 1999-07-14 08:33:38 by simonmar]
[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, fromInt{-glaExt-}),
47     Real(..),
48     Integral(quot, rem, div, mod, quotRem, divMod, toInteger, toInt{-partain-}),
49     Fractional(..),
50     Floating(..),
51     RealFrac(..),
52     RealFloat(..),
53
54         -- From Monad
55     Monad(..),
56     Functor(..), 
57     mapM, mapM_, sequence, sequence_, (=<<),
58
59     maybe, either,
60     (&&), (||), not, otherwise,
61     subtract, even, odd, gcd, lcm, (^), (^^), 
62     fromIntegral, realToFrac,
63     --exported by PrelTup: fst, snd, curry, uncurry,
64     id, const, (.), flip, ($), until,
65     asTypeOf, error, undefined,
66     seq, ($!)
67
68   ) where
69
70 import PrelBase
71 import PrelList hiding ( takeUInt_append )
72 import PrelRead
73 import PrelEnum
74 import PrelNum
75 import PrelNumExtra
76 import PrelTup
77 import PrelMaybe
78 import PrelShow
79 import PrelConc
80 import Monad
81 import Maybe
82 import PrelErr   ( error )
83 import IO
84
85 infixr 0 $!
86
87 ($!)    :: (a -> b) -> a -> b
88 f $! x  = x `seq` f x
89
90 -- It is expected that compilers will recognize this and insert error
91 -- messages which are more appropriate to the context in which undefined 
92 -- appears. 
93
94 undefined               :: a
95 undefined               =  error "Prelude.undefined"
96 \end{code}
97
98
99 List sum and product are defined here because PrelList is too far
100 down the compilation chain to "see" the Num class.
101
102 \begin{code}
103 -- sum and product compute the sum or product of a finite list of numbers.
104 {-# SPECIALISE sum     :: [Int] -> Int #-}
105 {-# SPECIALISE sum     :: [Integer] -> Integer #-}
106 {-# SPECIALISE product :: [Int] -> Int #-}
107 {-# SPECIALISE product :: [Integer] -> Integer #-}
108 sum, product            :: (Num a) => [a] -> a
109 #ifdef USE_REPORT_PRELUDE
110 sum                     =  foldl (+) 0  
111 product                 =  foldl (*) 1
112 #else
113 sum     l       = sum' l 0
114   where
115     sum' []     a = a
116     sum' (x:xs) a = sum' xs (a+x)
117 product l       = prod l 1
118   where
119     prod []     a = a
120     prod (x:xs) a = prod xs (a*x)
121 #endif
122 \end{code}