FirstPrelude 0.1.2.0 → 0.2.0.0
raw patch · 2 files changed
+86/−14 lines, 2 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
- FirstPrelude: infixl 9 !!
+ FirstPrelude: and :: [Bool] -> Bool
+ FirstPrelude: concat :: Foldable t => t [a] -> [a]
+ FirstPrelude: concatMap :: Foldable t => (a -> [b]) -> t a -> [b]
+ FirstPrelude: eqChar :: Char -> Char -> Bool
+ FirstPrelude: eqString :: String -> String -> Bool
+ FirstPrelude: or :: [Bool] -> Bool
- FirstPrelude: (!!) :: [a] -> Int -> a
+ FirstPrelude: (!!) :: [a] -> Integer -> a
- FirstPrelude: class Show a
+ FirstPrelude: class () => Show a
- FirstPrelude: cycle :: [a] -> [a]
+ FirstPrelude: cycle :: HasCallStack => [a] -> [a]
- FirstPrelude: data Bool
+ FirstPrelude: data () => Bool
- FirstPrelude: data Char
+ FirstPrelude: data () => Char
- FirstPrelude: data Either a b
+ FirstPrelude: data () => Either a b
- FirstPrelude: data IO a
+ FirstPrelude: data () => IO a
- FirstPrelude: data Integer
+ FirstPrelude: data () => Integer
- FirstPrelude: data Maybe a
+ FirstPrelude: data () => Maybe a
- FirstPrelude: drop :: Int -> [a] -> [a]
+ FirstPrelude: drop :: Integer -> [a] -> [a]
- FirstPrelude: error :: forall (r :: RuntimeRep) (a :: TYPE r). HasCallStack => [Char] -> a
+ FirstPrelude: error :: String -> a
- FirstPrelude: replicate :: Int -> a -> [a]
+ FirstPrelude: replicate :: Integer -> a -> [a]
- FirstPrelude: splitAt :: Int -> [a] -> ([a], [a])
+ FirstPrelude: splitAt :: Integer -> [a] -> ([a], [a])
- FirstPrelude: take :: Int -> [a] -> [a]
+ FirstPrelude: take :: Integer -> [a] -> [a]
- FirstPrelude: undefined :: forall (r :: RuntimeRep) (a :: TYPE r). HasCallStack => a
+ FirstPrelude: undefined :: a
Files
- FirstPrelude.cabal +2/−2
- src/FirstPrelude.hs +84/−12
FirstPrelude.cabal view
@@ -8,7 +8,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 0.1.2.0+version: 0.2.0.0 -- A short (one-line) description of the package. synopsis: A version of Prelude suitable for teaching.@@ -53,7 +53,7 @@ -- other-extensions: -- Other library packages from which modules are imported.- build-depends: base >= 4.0.0.0 && < 4.16.5.0+ build-depends: base >= 4.0.0.0 && < 5 -- Directories containing source files. hs-source-dirs: src
src/FirstPrelude.hs view
@@ -42,6 +42,7 @@ either, Char, String,+ eqChar, eqString, -- *** Tuples fst, snd, curry, uncurry,@@ -56,7 +57,7 @@ -- ** Numbers - -- *** Only Integers for now folks+ -- *** Just expose Integer Integer, -- *** Numeric operations@@ -79,19 +80,20 @@ seq, -- * List operations- List.map, (List.++), List.filter,- List.head, List.last, List.tail, List.init, (List.!!),+ and, or,+ List.map, (List.++), List.filter, List.concat, List.concatMap,+ head, last, tail, init, (!!), null, length, List.reverse, -- *** Scans List.scanl, List.scanl1, List.scanr, List.scanr1, -- *** Infinite lists- List.iterate, List.repeat, List.replicate, List.cycle,+ List.iterate, List.repeat, replicate, List.cycle, -- ** Sublists- List.take, List.drop,+ take, drop, List.takeWhile, List.dropWhile, List.span, List.break,- List.splitAt,+ splitAt, -- ** Zipping and unzipping lists List.zip, List.zip3, List.zipWith, List.zipWith3,@@ -134,7 +136,8 @@ import Data.Maybe import Data.Tuple -import GHC.Base hiding ( foldr, mapM, sequence, Eq(..), Ord(..), Monad(..) )+import GHC.Base hiding ( foldr, mapM, sequence, Eq(..), Ord(..), Monad(..), eqChar, eqString, error, undefined )+import qualified GHC.Err import qualified Text.Read as Read import qualified GHC.Enum as Enum import qualified GHC.Num as Num@@ -151,16 +154,19 @@ default (Integer) --- So that RebindableSyntax can also be used+-- So that RebindableSyntax can also be used (though this is optional) ifThenElse :: Bool -> a -> a -> a ifThenElse True x _ = x ifThenElse False _ y = y --- Avoids the Int/Integer problem-length :: [a] -> Integer-length [] = 0-length (_:xs) = 1 + length xs+-- ** Monomorphised equality for Char and String +eqChar :: Char -> Char -> Bool+eqChar = (Eq.==)++eqString :: String -> String -> Bool+eqString = (Eq.==)+ -- ** Monomorphised comparisons and arithmetic (==), (/=), (<), (<=), (>=), (>) :: Integer -> Integer -> Bool@@ -214,6 +220,64 @@ (^) :: Integer -> Integer -> Integer (^) = (NumR.^) +-- ** List functions++-- Avoids the Int/Integer problem+length :: [a] -> Integer+length [] = 0+length (_:xs) = 1 + length xs++take :: Integer -> [a] -> [a]+take n _ | n <= 0 = []+take _ [] = []+take n (x:xs) = x : take (n-1) xs++drop :: Integer -> [a] -> [a]+drop n xs | n <= 0 = xs+drop _ [] = []+drop n (_:xs) = drop (n-1) xs++replicate :: Integer -> a -> [a]+replicate n x | n <= 0 = []+replicate n x = x : replicate (n-1) x++splitAt :: Integer -> [a] -> ([a], [a])+splitAt n xs | n <= 0 = ([], xs)+splitAt _ [] = ([], [])+splitAt n (x:xs) = let (ys, zs) = splitAt (n-1) xs in (x:ys, zs)++and :: [Bool] -> Bool+and [] = True+and (b : bs) = b && and bs++or :: [Bool] -> Bool+or [] = False+or (b : bs) = b || or bs++(!!) :: [a] -> Integer -> a+(x:_) !! n | n == 0 = x+(_:xs) !! n | n > 0 = xs !! (n - 1)+_ !! _ = error "FirstPrelude.!!: index out of bounds"++-- Overriding these partial functions to remove HasCallStack constraint+head :: [a] -> a+head (x:_) = x+head [] = error "FirstPrelude.head: empty list"++tail :: [a] -> [a]+tail (_:xs) = xs+tail [] = error "FirstPrelude.tail: empty list"++last :: [a] -> a+last [x] = x+last (_:xs) = last xs+last [] = error "FirstPrelude.last: empty list"++init :: [a] -> [a]+init [_] = []+init (x:xs) = x : init xs+init [] = error "FirstPrelude.init: empty list"+ -- ** Monomorphised fold things null :: [a] -> Bool@@ -238,6 +302,14 @@ fail :: String -> IO a fail = (Monad.fail)++-- ** Overriding error and undefined to remove HasCallStack constraint++error :: String -> a+error = GHC.Err.error++undefined :: a+undefined = GHC.Err.undefined -- ** Show gets a fancy error message