basic-prelude-0.7.0/src/0000755000000000000000000000000013211417466013217 5ustar0000000000000000basic-prelude-0.7.0/src/BasicPrelude.hs0000644000000000000000000001551013211234734016112 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE CPP #-} -- | BasicPrelude mostly re-exports -- several key libraries in their entirety. -- The exception is Data.List, -- where various functions are replaced -- by similar versions that are either -- generalized, operate on Text, -- or are implemented strictly. module BasicPrelude ( -- * Module exports module CorePrelude , module Data.List , module Control.Monad -- ** Folds and traversals , Foldable ( foldMap , foldr , foldr' , foldl , foldl' , foldr1 , foldl1 ) -- In base-4.8, these are instance methods. , elem , maximum , minimum , traverse_ , sequenceA_ , for_ , maximumBy , minimumBy , Traversable ( traverse , sequenceA , mapM , sequence ) , for -- * Enhanced exports -- ** Simpler name for a typeclassed operation , map , empty , (++) , concat , intercalate -- ** Strict implementation , BasicPrelude.sum , BasicPrelude.product -- ** Text for Read and Show operations , tshow , fromShow , read , readIO -- ** FilePath for file operations , readFile , writeFile , appendFile -- * Text exports -- ** Text operations (Pure) , Text.lines , Text.words , Text.unlines , Text.unwords , textToString , ltextToString , fpToText , fpFromText , fpToString , encodeUtf8 , decodeUtf8 -- ** Text operations (IO) , getLine , getContents , interact -- * Miscellaneous prelude re-exports -- ** Math , Prelude.gcd , Prelude.lcm -- ** Show and Read , Prelude.Show (..) , Prelude.ShowS , Prelude.shows , Prelude.showChar , Prelude.showString , Prelude.showParen , Prelude.ReadS , Prelude.readsPrec , Prelude.readList , Prelude.reads , Prelude.readParen , Prelude.lex , readMay -- ** IO operations , getChar , putChar , readLn ) where import CorePrelude import Data.List hiding ( -- prefer monoid versions instead (++) , concat , intercalate -- prefer Text versions instead , lines , words , unlines , unwords -- prefer map = fmap instead , map -- prefer strict versions , sum , product -- prefer Foldable versions , elem , foldl , foldl' , foldl1 , foldr , foldr1 , maximum , minimum , maximumBy , minimumBy ) -- Import *all of the things* from Control.Monad, -- specifically, the list-based things that -- CorePrelude doesn't export import Control.Monad hiding ( -- Also exported by Data.Traversable. mapM , sequence ) import Data.Foldable (Foldable(..), elem, maximum, minimum, traverse_, sequenceA_, for_) import Data.Traversable (Traversable(..), for) import qualified Data.Text as Text import qualified Data.Text.IO as Text import qualified Data.Text.Lazy as LText import qualified Data.Text.Lazy.IO as LText import qualified Prelude import Data.Text.Encoding (encodeUtf8, decodeUtf8With) import Data.Text.Encoding.Error (lenientDecode) import qualified Text.Read #if MIN_VERSION_base(4,10,0) import Data.Foldable (maximumBy, minimumBy) #else maximumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a maximumBy cmp = foldl1 max' where max' x y = case cmp x y of GT -> x _ -> y minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a minimumBy cmp = foldl1 min' where min' x y = case cmp x y of GT -> y _ -> x #endif -- | > map = fmap map :: (Functor f) => (a -> b) -> f a -> f b map = fmap -- | > empty = mempty empty :: Monoid w => w empty = mempty {-# DEPRECATED empty "Use mempty" #-} infixr 5 ++ -- | > (++) = mappend (++) :: Monoid w => w -> w -> w (++) = mappend -- | > concat = mconcat concat :: Monoid w => [w] -> w concat = mconcat -- | > intercalate = mconcat .: intersperse intercalate :: Monoid w => w -> [w] -> w intercalate xs xss = mconcat (Data.List.intersperse xs xss) -- | Compute the sum of a finite list of numbers. sum :: (Foldable f, Num a) => f a -> a sum = Data.Foldable.foldl' (+) 0 -- | Compute the product of a finite list of numbers. product :: (Foldable f, Num a) => f a -> a product = Data.Foldable.foldl' (*) 1 -- | Convert a value to readable Text -- -- @since 0.6.0 tshow :: Show a => a -> Text tshow = Text.pack . Prelude.show -- | Convert a value to readable IsString -- -- Since 0.3.12 fromShow :: (Show a, IsString b) => a -> b fromShow = fromString . Prelude.show -- | Parse Text to a value read :: Read a => Text -> a read = Prelude.read . Text.unpack -- | The readIO function is similar to read -- except that it signals parse failure to the IO monad -- instead of terminating the program. -- -- @since 0.7.0 readIO :: (MonadIO m, Read a) => Text -> m a readIO = liftIO . Prelude.readIO . Text.unpack -- | Read a file and return the contents of the file as Text. -- The entire file is read strictly. -- -- @since 0.7.0 readFile :: MonadIO m => FilePath -> m Text readFile = liftIO . Text.readFile -- | Write Text to a file. -- The file is truncated to zero length before writing begins. -- -- @since 0.7.0 writeFile :: MonadIO m => FilePath -> Text -> m () writeFile p = liftIO . Text.writeFile p -- | Write Text to the end of a file. -- -- @since 0.7.0 appendFile :: MonadIO m => FilePath -> Text -> m () appendFile p = liftIO . Text.appendFile p textToString :: Text -> Prelude.String textToString = Text.unpack ltextToString :: LText -> Prelude.String ltextToString = LText.unpack -- | This function assumes file paths are encoded in UTF8. If it -- cannot decode the 'FilePath', the result is just an approximation. -- -- Since 0.3.13 fpToText :: FilePath -> Text fpToText = Text.pack {-# DEPRECATED fpToText "Use Data.Text.pack" #-} -- | -- Since 0.3.13 fpFromText :: Text -> FilePath fpFromText = Text.unpack {-# DEPRECATED fpFromText "Use Data.Text.unpack" #-} -- | -- Since 0.3.13 fpToString :: FilePath -> Prelude.String fpToString = id {-# DEPRECATED fpToString "Use id" #-} -- | Note that this is /not/ the standard @Data.Text.Encoding.decodeUtf8@. That -- function will throw impure exceptions on any decoding errors. This function -- instead uses @decodeLenient@. decodeUtf8 :: ByteString -> Text decodeUtf8 = decodeUtf8With lenientDecode -- | -- @since 0.7.0 getLine :: MonadIO m => m Text getLine = liftIO Text.getLine -- | -- @since 0.7.0 getContents :: MonadIO m => m LText getContents = liftIO LText.getContents -- | -- @since 0.7.0 interact :: MonadIO m => (LText -> LText) -> m () interact = liftIO . LText.interact readMay :: Read a => Text -> Maybe a readMay = Text.Read.readMaybe . Text.unpack -- | -- @since 0.7.0 getChar :: MonadIO m => m Char getChar = liftIO Prelude.getChar -- | -- @since 0.7.0 putChar :: MonadIO m => Char -> m () putChar = liftIO . Prelude.putChar -- | The 'readLn' function combines 'getLine' and 'readIO'. -- -- @since 0.7.0 readLn :: (MonadIO m, Read a) => m a readLn = liftIO Prelude.readLn basic-prelude-0.7.0/src/CorePrelude.hs0000644000000000000000000001373613211417466015776 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE CPP #-} module CorePrelude ( -- * Standard -- ** Operators (Prelude.$) , (Prelude.$!) , (Prelude.&&) , (Prelude.||) , (Control.Category..) -- ** Functions , Prelude.not , Prelude.otherwise , Prelude.fst , Prelude.snd , Control.Category.id , Prelude.maybe , Prelude.either , Prelude.flip , Prelude.const , Prelude.error , putStr , putStrLn , print , getArgs , terror , Prelude.odd , Prelude.even , Prelude.uncurry , Prelude.curry , Data.Tuple.swap , Prelude.until , Prelude.asTypeOf , Prelude.undefined , Prelude.seq -- ** Type classes , Prelude.Ord (..) , Prelude.Eq (..) , Prelude.Bounded (..) , Prelude.Enum (..) , Prelude.Show , Prelude.Read , Prelude.Functor (..) , Prelude.Monad (..) , (Control.Monad.=<<) , Data.String.IsString (..) -- ** Numeric type classes , Prelude.Num (..) , Prelude.Real (..) , Prelude.Integral (..) , Prelude.Fractional (..) , Prelude.Floating (..) , Prelude.RealFrac (..) , Prelude.RealFloat(..) -- ** Data types , Prelude.Maybe (..) , Prelude.Ordering (..) , Prelude.Bool (..) , Prelude.Char , Prelude.IO , Prelude.Either (..) -- * Re-exports -- ** Packed reps , ByteString , LByteString , Text , LText -- ** Containers , Map , HashMap , IntMap , Set , HashSet , IntSet , Seq , Vector , UVector , Unbox , SVector , Data.Vector.Storable.Storable , Hashable -- ** Numbers , Word , Word8 , Word32 , Word64 , Prelude.Int , Int32 , Int64 , Prelude.Integer , Prelude.Rational , Prelude.Float , Prelude.Double -- ** Numeric functions , (Prelude.^) , (Prelude.^^) , Prelude.subtract , Prelude.fromIntegral , Prelude.realToFrac -- ** Monoids , Monoid (..) , (<>) -- ** Folds and traversals , Data.Foldable.Foldable , Data.Foldable.asum , Data.Traversable.Traversable -- ** arrow , Control.Arrow.first , Control.Arrow.second , (Control.Arrow.***) , (Control.Arrow.&&&) -- ** Bool , bool -- ** Maybe , Data.Maybe.mapMaybe , Data.Maybe.catMaybes , Data.Maybe.fromMaybe , Data.Maybe.isJust , Data.Maybe.isNothing , Data.Maybe.listToMaybe , Data.Maybe.maybeToList -- ** Either , Data.Either.partitionEithers , Data.Either.lefts , Data.Either.rights -- ** Ord , Data.Function.on , Data.Ord.comparing , equating , GHC.Exts.Down (..) -- ** Applicative , Control.Applicative.Applicative (..) , (Control.Applicative.<$>) , (Control.Applicative.<|>) -- ** Monad , (Control.Monad.>=>) -- ** Transformers , Control.Monad.Trans.Class.lift , Control.Monad.IO.Class.MonadIO , Control.Monad.IO.Class.liftIO -- ** Exceptions , Control.Exception.Exception (..) , Data.Typeable.Typeable (..) , Control.Exception.SomeException , Control.Exception.IOException , module System.IO.Error -- ** Files , Prelude.FilePath , (F.) , (F.<.>) -- ** Strings , Prelude.String -- ** Hashing , hash , hashWithSalt ) where import qualified Prelude import Prelude (Char, (.), Eq, Bool) import Data.Hashable (Hashable, hash, hashWithSalt) import Data.Vector.Unboxed (Unbox) import Data.Monoid (Monoid (..)) import qualified Control.Arrow import Control.Applicative import qualified Control.Category import qualified Control.Monad import qualified Control.Exception import qualified Data.Typeable import qualified Data.Foldable import qualified Data.Traversable import Data.Word (Word8, Word32, Word64, Word) import Data.Int (Int32, Int64) import qualified Data.Text.IO import qualified Data.Maybe import qualified Data.Either import qualified Data.Ord import qualified Data.Function import qualified Data.Tuple import qualified Data.String import qualified Control.Monad.Trans.Class import qualified Control.Monad.IO.Class import Control.Monad.IO.Class (MonadIO (liftIO)) import Data.ByteString (ByteString) import qualified Data.ByteString.Lazy import Data.Text (Text) import qualified Data.Text.Lazy import Data.Vector (Vector) import qualified Data.Vector.Unboxed import qualified Data.Vector.Storable import Data.Map (Map) import Data.Set (Set) import Data.IntMap (IntMap) import Data.IntSet (IntSet) import Data.Sequence (Seq) import Data.HashMap.Strict (HashMap) import Data.HashSet (HashSet) import qualified System.FilePath as F import qualified System.Environment import qualified Data.Text import qualified Data.List import System.IO.Error hiding (catch, try) import qualified GHC.Exts #if MIN_VERSION_base(4,7,0) import Data.Bool (bool) #endif #if MIN_VERSION_base(4,5,0) import Data.Monoid ((<>)) #endif #if MIN_VERSION_base(4,9,0) import GHC.Stack (HasCallStack) #endif type LText = Data.Text.Lazy.Text type LByteString = Data.ByteString.Lazy.ByteString type UVector = Data.Vector.Unboxed.Vector type SVector = Data.Vector.Storable.Vector #if !MIN_VERSION_base(4,7,0) bool :: a -> a -> Bool -> a bool f t b = if b then t else f #endif #if !MIN_VERSION_base(4,5,0) infixr 6 <> (<>) :: Monoid w => w -> w -> w (<>) = mappend {-# INLINE (<>) #-} #endif equating :: Eq a => (b -> a) -> b -> b -> Bool equating = Data.Function.on (Prelude.==) getArgs :: MonadIO m => m [Text] getArgs = liftIO (Data.List.map Data.Text.pack <$> System.Environment.getArgs) putStr :: MonadIO m => Text -> m () putStr = liftIO . Data.Text.IO.putStr putStrLn :: MonadIO m => Text -> m () putStrLn = liftIO . Data.Text.IO.putStrLn print :: (MonadIO m, Prelude.Show a) => a -> m () print = liftIO . Prelude.print -- | @error@ applied to @Text@ -- -- Since 0.4.1 #if MIN_VERSION_base(4,9,0) terror :: HasCallStack => Text -> a #else terror :: Text -> a #endif terror = Prelude.error . Data.Text.unpack basic-prelude-0.7.0/LICENSE0000644000000000000000000000207512714017574013444 0ustar0000000000000000Copyright (c) 2012 Michael Snoyman, http://www.yesodweb.com/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. basic-prelude-0.7.0/Setup.hs0000644000000000000000000000005612714017574014070 0ustar0000000000000000import Distribution.Simple main = defaultMain basic-prelude-0.7.0/basic-prelude.cabal0000644000000000000000000000234313211235151016122 0ustar0000000000000000-- This file has been generated from package.yaml by hpack version 0.20.0. -- -- see: https://github.com/sol/hpack -- -- hash: 9e2114ea9be10fb6a3831b21030119adfd0bc5db6f95b840818e819bb39d4cb5 name: basic-prelude version: 0.7.0 synopsis: An enhanced core prelude; a common foundation for alternate preludes. description: Please see the README on Github at category: Control, Prelude homepage: https://github.com/snoyberg/basic-prelude#readme bug-reports: https://github.com/snoyberg/basic-prelude/issues author: Michael Snoyman, Dan Burton maintainer: michael@snoyman.com license: MIT license-file: LICENSE build-type: Simple cabal-version: >= 1.10 extra-source-files: ChangeLog.md README.md source-repository head type: git location: https://github.com/snoyberg/basic-prelude library hs-source-dirs: src build-depends: base >=4.6 && <5 , bytestring , containers , filepath , hashable , text , transformers , unordered-containers , vector exposed-modules: BasicPrelude CorePrelude other-modules: Paths_basic_prelude default-language: Haskell2010 basic-prelude-0.7.0/ChangeLog.md0000644000000000000000000000372013211417466014603 0ustar0000000000000000## 0.7.0 * Export applicative version of Foldable and Traversable functions [#72](https://github.com/snoyberg/basic-prelude/issues/72) * Generalize all IO functions to MonadIO [#75](https://github.com/snoyberg/basic-prelude/issues/75) * Use `foldl1` for `maximumBy` and `minimumBy` [#74](https://github.com/snoyberg/basic-prelude/issues/74) * Remove nonexistent `foldr'` from `Data.List` hiding list * Remove the `lifted-base` dependency. This means that `CorePrelude` and `BasicPrelude` no longer expose any exception handling functions. This is intentional: the new recommendations from this library are to use an async-exception-aware exception handling library, either [safe-exceptions](https://haskell-lang.org/library/safe-exceptions) or [unliftio](https://www.stackage.org/package/unliftio). ## 0.6.1.1 * Add `HasCallStack` for `terror` ## 0.6.1 * Generalize `sum` and `product` to `Foldable` [#69](https://github.com/snoyberg/basic-prelude/issues/69) ## 0.6.0 * Export `show` from `Show` typeclass, and rename current `show` to `tshow` [#67](https://github.com/snoyberg/basic-prelude/issues/67) ## 0.5.2 * Expose `bool` ## 0.5.1 * Expose `asum` * Deprecate `empty` (so it can be replaced with `Alternative`'s `empty`) ## 0.5.0 * Expose more Foldable/Traversable stuff ## 0.4.1 * terror ## 0.4.0 * Drop system-filepath ## 0.3.13 * Export converters between FilePath <-> Text, String. [#56](https://github.com/snoyberg/basic-prelude/pull/56) ## 0.3.12 * Add `fromShow` [#55](https://github.com/snoyberg/basic-prelude/pull/55) ## 0.3.11 * [Generalize `print`](https://github.com/snoyberg/basic-prelude/pull/51) ## 0.3 * Moved a number of exports from @BasicPrelude@ to @CorePrelude@ and vice-versa. ## 0.2 * Renamed `BasicPrelude` to `CorePrelude` and added a new @BasicPrelude@ module provided a full-featured `Prelude` alternative. Also added a number of new exports. ## 0.1 * Initial version, code taken from @classy-prelude@ with a few minor tweaks. basic-prelude-0.7.0/README.md0000644000000000000000000000163112714017574013713 0ustar0000000000000000basic-prelude ============= The premise of `basic-prelude` is that there are a lot of very commonly desired features missing from the standard `Prelude`, such as commonly used operators (`<$>` and `>=>`, for instance) and imports for common datatypes (e.g., `ByteString` and `Vector`). At the same time, there are lots of other components which are more debatable, such as providing polymorphic versions of common functions. So `basic-prelude` is intended to give a common foundation for a number of alternate preludes. The package provides two modules: `CorePrelude` provides the common ground for other preludes to build on top of, while `BasicPrelude` exports `CorePrelude` together with commonly used list functions to provide a drop-in replacement for the standard `Prelude`. Users wishing to have an improved `Prelude` can use `BasicPrelude`. Developers wishing to create a new prelude should use `CorePrelude`.