base: Remove `Monad(fail)` method and reexport `MonadFail(fail)` instead
[ghc.git] / libraries / base / Prelude.hs
1 {-# LANGUAGE Trustworthy #-}
2 {-# LANGUAGE NoImplicitPrelude #-}
3
4 -----------------------------------------------------------------------------
5 -- |
6 -- Module : Prelude
7 -- Copyright : (c) The University of Glasgow 2001
8 -- License : BSD-style (see the file libraries/base/LICENSE)
9 --
10 -- Maintainer : libraries@haskell.org
11 -- Stability : stable
12 -- Portability : portable
13 --
14 -- The Prelude: a standard module. The Prelude is imported by default
15 -- into all Haskell modules unless either there is an explicit import
16 -- statement for it, or the NoImplicitPrelude extension is enabled.
17 --
18 -----------------------------------------------------------------------------
19
20 module Prelude (
21
22 -- * Standard types, classes and related functions
23
24 -- ** Basic data types
25 Bool(False, True),
26 (&&), (||), not, otherwise,
27
28 Maybe(Nothing, Just),
29 maybe,
30
31 Either(Left, Right),
32 either,
33
34 Ordering(LT, EQ, GT),
35 Char, String,
36
37 -- *** Tuples
38 fst, snd, curry, uncurry,
39
40 -- ** Basic type classes
41 Eq((==), (/=)),
42 Ord(compare, (<), (<=), (>=), (>), max, min),
43 Enum(succ, pred, toEnum, fromEnum, enumFrom, enumFromThen,
44 enumFromTo, enumFromThenTo),
45 Bounded(minBound, maxBound),
46
47 -- ** Numbers
48
49 -- *** Numeric types
50 Int, Integer, Float, Double,
51 Rational, Word,
52
53 -- *** Numeric type classes
54 Num((+), (-), (*), negate, abs, signum, fromInteger),
55 Real(toRational),
56 Integral(quot, rem, div, mod, quotRem, divMod, toInteger),
57 Fractional((/), recip, fromRational),
58 Floating(pi, exp, log, sqrt, (**), logBase, sin, cos, tan,
59 asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh),
60 RealFrac(properFraction, truncate, round, ceiling, floor),
61 RealFloat(floatRadix, floatDigits, floatRange, decodeFloat,
62 encodeFloat, exponent, significand, scaleFloat, isNaN,
63 isInfinite, isDenormalized, isIEEE, isNegativeZero, atan2),
64
65 -- *** Numeric functions
66 subtract, even, odd, gcd, lcm, (^), (^^),
67 fromIntegral, realToFrac,
68
69 -- ** Semigroups and Monoids
70 Semigroup((<>)),
71 Monoid(mempty, mappend, mconcat),
72
73 -- ** Monads and functors
74 Functor(fmap, (<$)), (<$>),
75 Applicative(pure, (<*>), (*>), (<*)),
76 Monad((>>=), (>>), return),
77 MonadFail(fail),
78 mapM_, sequence_, (=<<),
79
80 -- ** Folds and traversals
81 Foldable(elem, -- :: (Foldable t, Eq a) => a -> t a -> Bool
82 -- fold, -- :: Monoid m => t m -> m
83 foldMap, -- :: Monoid m => (a -> m) -> t a -> m
84 foldr, -- :: (a -> b -> b) -> b -> t a -> b
85 -- foldr', -- :: (a -> b -> b) -> b -> t a -> b
86 foldl, -- :: (b -> a -> b) -> b -> t a -> b
87 -- foldl', -- :: (b -> a -> b) -> b -> t a -> b
88 foldr1, -- :: (a -> a -> a) -> t a -> a
89 foldl1, -- :: (a -> a -> a) -> t a -> a
90 maximum, -- :: (Foldable t, Ord a) => t a -> a
91 minimum, -- :: (Foldable t, Ord a) => t a -> a
92 product, -- :: (Foldable t, Num a) => t a -> a
93 sum), -- :: Num a => t a -> a
94 -- toList) -- :: Foldable t => t a -> [a]
95
96 Traversable(traverse, sequenceA, mapM, sequence),
97
98 -- ** Miscellaneous functions
99 id, const, (.), flip, ($), until,
100 asTypeOf, error, errorWithoutStackTrace, undefined,
101 seq, ($!),
102
103 -- * List operations
104 map, (++), filter,
105 head, last, tail, init, null, length, (!!),
106 reverse,
107 -- *** Special folds
108 and, or, any, all,
109 concat, concatMap,
110 -- ** Building lists
111 -- *** Scans
112 scanl, scanl1, scanr, scanr1,
113 -- *** Infinite lists
114 iterate, repeat, replicate, cycle,
115 -- ** Sublists
116 take, drop, splitAt, takeWhile, dropWhile, span, break,
117 -- ** Searching lists
118 notElem, lookup,
119 -- ** Zipping and unzipping lists
120 zip, zip3, zipWith, zipWith3, unzip, unzip3,
121 -- ** Functions on strings
122 lines, words, unlines, unwords,
123
124 -- * Converting to and from @String@
125 -- ** Converting to @String@
126 ShowS,
127 Show(showsPrec, showList, show),
128 shows,
129 showChar, showString, showParen,
130 -- ** Converting from @String@
131 ReadS,
132 Read(readsPrec, readList),
133 reads, readParen, read, lex,
134
135 -- * Basic Input and output
136 IO,
137 -- ** Simple I\/O operations
138 -- All I/O functions defined here are character oriented. The
139 -- treatment of the newline character will vary on different systems.
140 -- For example, two characters of input, return and linefeed, may
141 -- read as a single newline character. These functions cannot be
142 -- used portably for binary I/O.
143 -- *** Output functions
144 putChar,
145 putStr, putStrLn, print,
146 -- *** Input functions
147 getChar,
148 getLine, getContents, interact,
149 -- *** Files
150 FilePath,
151 readFile, writeFile, appendFile, readIO, readLn,
152 -- ** Exception handling in the I\/O monad
153 IOError, ioError, userError,
154
155 ) where
156
157 import Control.Monad
158 import System.IO
159 import System.IO.Error
160 import Data.List
161 import Data.Either
162 import Data.Foldable ( Foldable(..) )
163 import Data.Functor ( (<$>) )
164 import Data.Maybe
165 import Data.Traversable ( Traversable(..) )
166 import Data.Tuple
167
168 import GHC.Base hiding ( foldr, mapM, sequence )
169 import Text.Read
170 import GHC.Enum
171 import GHC.Num
172 import GHC.Real
173 import GHC.Float
174 import GHC.Show