@@ -1,15 +1,322 @@
1+{-# LANGUAGE PackageImports #-}
12{-# LANGUAGE NoImplicitPrelude #-}
23
3−-- The intent is that this Prelude provide the API of
4−-- the base 4.11 Prelude in a way that is portable for
5−-- all base versions.
4+-- Amplified Prelude for pandoc
5+-- comment -- pandoc indicates pandoc additions
66
7−module Prelude
8−(
9− module Prelude.Compat
10−, Semigroup(..)
11−)
12−where
7+module Prelude (
8+
9+ -- * Standard types, classes and related functions
10+
11+ -- ** Bool
12+ Bool(False, True),
13+ (&&), (||), not, otherwise,
14+
15+ -- ** Maybe
16+ Maybe(Nothing, Just),
17+ maybe,
18+ isJust, isNothing, fromMaybe, -- pandoc
19+ listToMaybe, maybeToList, catMaybes, mapMaybe, -- pandoc
20+
21+ -- ** Either
22+ Either(Left, Right),
23+ either,
24+ lefts, rights, isLeft, isRight, -- pandoc
25+ fromLeft, fromRight, partitionEithers, -- pandoc
26+
27+ -- ** Ord
28+ Ordering(LT, EQ, GT),
29+ Ord(compare, (<), (<=), (>=), (>), max, min),
30+ comparing, -- pandoc
31+ Down, -- pandoc
32+
33+ -- ** Char and String
34+ Char, String,
35+ lines, words, unlines, unwords,
36+
37+ -- *** Tuples
38+ fst, snd, curry, uncurry,
39+ swap, -- pandoc
40+
41+ -- ** Basic type classes
42+ Eq((==), (/=)),
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+ MonadPlus (mzero, mplus), msum, -- pandoc
78+ MonadFail(fail),
79+ mapM_, sequence_, (=<<),
80+ forM_, (>=>), (<=<), forever, void, -- pandoc
81+ filterM, mfilter, join, zipWithM, zipWithM_, foldM, foldM_, -- pandoc
82+ replicateM, replicateM_, guard, when, unless, -- pandoc
83+ liftM, liftM2, liftM3, liftM4, liftM5, ap, (<$!>), -- pandoc
84+
85+ -- ** Folds and traversals
86+ Foldable.Foldable(elem, -- :: (Foldable t, Eq a) => a -> t a -> Bool
87+ fold, -- :: Monoid m => t m -> m -- pandoc
88+ foldMap, -- :: Monoid m => (a -> m) -> t a -> m
89+ foldr, -- :: (a -> b -> b) -> b -> t a -> b
90+ foldr', -- :: (a -> b -> b) -> b -> t a -> b -- pandoc
91+ -- foldl, -- :: (b -> a -> b) -> b -> t a -> b -- pandoc
92+ foldl' -- :: (b -> a -> b) -> b -> t a -> b -- pandoc
93+ -- foldr1, -- :: (a -> a -> a) -> t a -> a -- pandoc
94+ -- foldl1, -- :: (a -> a -> a) -> t a -> a -- pandoc
95+ -- maximum, -- :: (Foldable t, Ord a) => t a -> a
96+ -- minimum -- :: (Foldable t, Ord a) => t a -> a
97+ -- product, -- :: (Foldable t, Nu => t a -> a -- pandoc
98+ -- sum -- :: Num a => t a -> a -- pandoc
99+ -- toList -- :: Foldable t => t a -> [a] -- pandoc
100+ ),
101+ maximum, minimum, maximumMay, minimumMay, -- pandoc
102+ sum', product', -- pandoc
103+
104+ Traversable.Traversable(traverse, sequenceA, mapM, sequence),
105+ Traversable.for, Traversable.forM, -- pandoc
106+ Traversable.mapAccumL, Traversable.mapAccumR, -- pandoc
107+
108+ -- ** Miscellaneous functions
109+ id, const, (.), flip, ($), until,
110+ asTypeOf, error, errorWithoutStackTrace, undefined,
111+ seq, ($!),
112+
113+ -- * List operations
114+ List.map, (List.++), List.filter,
115+ -- List.head, List.last, List.tail, List.init, (List.!!), -- pandoc
116+ head, last, tail, init, (!!), -- pandoc
117+ headMay, lastMay, tailMay, initMay, (!!?), -- pandoc
118+ Foldable.null, Foldable.length,
119+ List.reverse,
120+ -- *** Special folds
121+ Foldable.and, Foldable.or, Foldable.any, Foldable.all,
122+ Foldable.concat, Foldable.concatMap,
123+ -- ** Building lists
124+ -- *** Scans
125+ List.scanl,
126+ -- List.scanl1, -- pandoc
127+ List.scanr,
128+ -- List.scanr1, -- pandoc
129+ -- *** Infinite lists
130+ List.iterate, List.repeat, List.replicate, List.cycle,
131+ -- ** Sublists
132+ List.take, List.drop,
133+ List.takeWhile, List.dropWhile,
134+ List.span, List.break,
135+ List.splitAt,
136+ List.isPrefixOf, List.isSuffixOf, List.isInfixOf, -- pandoc
137+ -- ** Searching lists
138+ Foldable.notElem,
139+ List.lookup,
140+ -- ** Zipping and unzipping lists
141+ List.zip, List.zip3,
142+ List.zipWith, List.zipWith3,
143+ List.unzip, List.unzip3,
144+
145+ -- * Converting to and from @String@
146+ -- ** Converting to @String@
147+ ShowS,
148+ Show(showsPrec, showList, show),
149+ shows,
150+ showChar, showString, showParen,
151+ -- ** Converting from @String@
152+ ReadS,
153+ Read(readsPrec, readList),
154+ reads,
155+ readParen,
156+ read, -- pandoc
157+ readMay, -- pandoc
158+ lex,
159+
160+ -- * Basic Input and output
161+ IO,
162+ -- ** Simple I\/O operations
163+ -- All I/O functions defined here are character oriented. The
164+ -- treatment of the newline character will vary on different systems.
165+ -- For example, two characters of input, return and linefeed, may
166+ -- read as a single newline character. These functions cannot be
167+ -- used portably for binary I/O.
168+ -- *** Output functions
169+ putChar,
170+ putStr, putStrLn, print,
171+ -- *** Input functions
172+ getChar,
173+ getLine, getContents, interact,
174+ -- *** Files
175+ FilePath,
176+ readFile, writeFile, appendFile, readIO, readLn,
177+ -- ** Exception handling in the I\/O monad
178+ IOError, ioError, userError,
179+
180+ -- ** Debugging
181+ traceShowId, traceShowIdWith, traceIO, trace, traceId, -- pandoc
182+ traceShow, traceM, traceShowM, traceStack, -- pandoc
183+ traceEvent, traceEventIO, traceMarker, traceMarkerIO, -- pandoc
184+
185+ -- ** Generics
186+ module Data.Data, -- pandoc
187+ module Data.Typeable -- pandoc
188+
189+ ) where
190+
191+import "base" Prelude hiding (read, head, last, init, tail, (!!),
192+ maximum, minimum)
193+import qualified "base" Prelude as StandardPrelude
194+import Data.Maybe
195+import Data.Char hiding (Char)
196+import Data.Either
197+import Data.Ord
198+import qualified Data.List as List
199+import qualified Data.Foldable as Foldable
200+import qualified Data.Traversable as Traversable
201+import Data.Tuple (swap)
202+import Control.Monad
203+import qualified Debug.Trace as Trace
204+import Data.Data
205+import Data.Typeable
206+import qualified Data.String as String
207+import Safe (atMay, headMay, lastMay, initMay, tailMay, readMay)
208+-- TODO
209+
210+-- replacements for sum, product
211+-- nonempty?
212+-- generics?
213+-- applicative/alternative?
214+-- exceptions?
215+
216+{-# WARNING head "head is a partial function: use headMay instead." #-}
217+head :: [a] -> a
218+head = List.head
219+
220+{-# WARNING last "last is a partial function: use lastMay instead." #-}
221+last :: [a] -> a
222+last = List.last
223+
224+{-# WARNING init "init is a partial function: use initMay instead." #-}
225+init :: [a] -> [a]
226+init = List.init
227+
228+{-# WARNING tail "tail is a partial function: use tailMay instead." #-}
229+tail :: [a] -> [a]
230+tail = List.tail
231+
232+{-# WARNING (!!) "(!!) is a partial function: use (!!?) instead." #-}
233+(!!) :: [a] -> Int -> a
234+(!!) = (List.!!)
235+
236+{-# WARNING maximum "maximum is a partial function: use maximumMay instead." #-}
237+maximum :: (Foldable t, Ord a) => t a -> a
238+maximum = Foldable.maximum
239+
240+{-# WARNING minimum "minimum is a partial function: use minimumMay instead." #-}
241+minimum :: (Foldable t, Ord a) => t a -> a
242+minimum = Foldable.minimum
243+
244+(!!?) :: [a] -> Int -> Maybe a
245+(!!?) = Safe.atMay
246+
247+-- borrowed from Safe.Util:
248+liftMay :: (a -> Bool) -> (a -> b) -> (a -> Maybe b)
249+liftMay test func val
250+ | test val = Nothing
251+ | otherwise = Just $ func val
252+
253+maximumMay :: (Foldable t, Ord a) => t a -> Maybe a
254+maximumMay = liftMay Foldable.null Foldable.maximum
255+
256+minimumMay :: (Foldable t, Ord a) => t a -> Maybe a
257+minimumMay = liftMay Foldable.null Foldable.minimum
258+
259+{-# WARNING read "read is a partial function: use readMay instead." #-}
260+read :: Read a => String -> a
261+read = StandardPrelude.read
262+
263+-- | Strict sum.
264+sum' :: (Foldable t, Num a) => t a -> a
265+sum' x = Foldable.foldl' (+) 0 x
266+
267+-- | Strict product.
268+product' :: (Foldable t, Num a) => t a -> a
269+product' x = Foldable.foldl' (*) 0 x
270+
271+{-# WARNING traceShowId "traceShowId left in code" #-}
272+traceShowId :: Show a => a -> a
273+traceShowId = Trace.traceShowId
274+
275+{-# WARNING traceShowIdWith "traceShowIdWith left in code" #-}
276+traceShowIdWith :: Show a => (String -> String) -> a -> a
277+traceShowIdWith f x = Trace.trace (f (show x)) x
278+
279+{-# WARNING traceIO "traceIO left in code" #-}
280+traceIO :: String -> IO ()
281+traceIO = Trace.traceIO
282+
283+{-# WARNING trace "trace left in code" #-}
284+trace :: String -> a -> a
285+trace = Trace.trace
286+
287+{-# WARNING traceId "traceId left in code" #-}
288+traceId :: String -> String
289+traceId = Trace.traceId
290+
291+{-# WARNING traceShow "traceShow left in code" #-}
292+traceShow :: Show a => a -> b -> b
293+traceShow = Trace.traceShow
294+
295+{-# WARNING traceM "traceM left in code" #-}
296+traceM :: Applicative f => String -> f ()
297+traceM = Trace.traceM
298+
299+{-# WARNING traceShowM "traceShowM left in code" #-}
300+traceShowM :: (Show a, Applicative f) => a -> f ()
301+traceShowM = Trace.traceShowM
302+
303+{-# WARNING traceStack "traceStack left in code" #-}
304+traceStack :: String -> a -> a
305+traceStack = Trace.traceStack
306+
307+{-# WARNING traceEvent "traceEvent left in code" #-}
308+traceEvent :: String -> a -> a
309+traceEvent = Trace.traceEvent
310+
311+{-# WARNING traceEventIO "traceIO left in code" #-}
312+traceEventIO :: String -> IO ()
313+traceEventIO = Trace.traceEventIO
314+
315+{-# WARNING traceMarker "traceMarker left in code" #-}
316+traceMarker :: String -> a -> a
317+traceMarker = Trace.traceMarker
318+
319+{-# WARNING traceMarkerIO "traceMarkerIO left in code" #-}
320+traceMarkerIO :: String -> IO ()
321+traceMarkerIO = Trace.traceMarkerIO
13322
14−import Prelude.Compat
15−import Data.Semigroup (Semigroup(..)) -- includes (<>)