basic-prelude-0.6.1.1/BasicPrelude.hs0000644000000000000000000001300212764225534015466 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} -- | 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 , Traversable ( traverse , sequenceA , mapM , sequence ) -- * 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) , Text.getLine , LText.getContents , LText.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 , Prelude.putChar , Prelude.getChar , Prelude.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 , foldr' , foldr1 , maximum , minimum ) -- 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) import Data.Traversable (Traversable(..)) 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 Safe -- | > 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. readIO :: Read a => Text -> IO a readIO = Prelude.readIO . Text.unpack -- | Read a file and return the contents of the file as Text. -- The entire file is read strictly. readFile :: FilePath -> IO Text readFile = Text.readFile -- | Write Text to a file. -- The file is truncated to zero length before writing begins. writeFile :: FilePath -> Text -> IO () writeFile = Text.writeFile -- | Write Text to the end of a file. appendFile :: FilePath -> Text -> IO () appendFile = Text.appendFile 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 readMay :: Read a => Text -> Maybe a readMay = Safe.readMay . Text.unpack basic-prelude-0.6.1.1/CorePrelude.hs0000644000000000000000000001547313056054414015343 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 , Control.Exception.Lifted.throwIO , Control.Exception.Lifted.try , Control.Exception.Lifted.tryJust , Control.Exception.Lifted.catch , Control.Exception.Lifted.catchJust , Control.Exception.Lifted.handle , Control.Exception.Lifted.handleJust , Control.Exception.Lifted.bracket , Control.Exception.Lifted.bracket_ , Control.Exception.Lifted.bracketOnError , Control.Exception.Lifted.onException , Control.Exception.Lifted.finally , Control.Exception.Lifted.mask , Control.Exception.Lifted.mask_ , Control.Exception.Lifted.uninterruptibleMask , Control.Exception.Lifted.uninterruptibleMask_ , module System.IO.Error -- ** Files , Prelude.FilePath , (F.) , (F.<.>) -- ** Strings , Prelude.String -- ** Hashing , hash , hashWithSalt -- ** Command line args , readArgs ) 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 Control.Exception.Lifted 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 ReadArgs 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 readArgs :: (MonadIO m, ReadArgs.ArgumentTuple a) => m a readArgs = liftIO ReadArgs.readArgs -- | @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.6.1.1/LICENSE0000644000000000000000000000207512714017574013603 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.6.1.1/Setup.hs0000644000000000000000000000005612714017574014227 0ustar0000000000000000import Distribution.Simple main = defaultMain basic-prelude-0.6.1.1/basic-prelude.cabal0000644000000000000000000000400313056054444016267 0ustar0000000000000000name: basic-prelude version: 0.6.1.1 synopsis: An enhanced core prelude; a common foundation for alternate preludes. description: 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@. homepage: https://github.com/snoyberg/basic-prelude license: MIT license-file: LICENSE author: Michael Snoyman, Dan Burton maintainer: michael@snoyman.com extra-source-files: README.md ChangeLog.md category: Control, Prelude build-type: Simple cabal-version: >=1.8 library exposed-modules: BasicPrelude, CorePrelude build-depends: base >= 4.6 && < 5 , hashable , bytestring , text , transformers , containers , unordered-containers , vector , ReadArgs >= 1.2 && < 1.3 , lifted-base , safe , filepath source-repository head type: git location: git://github.com/snoyberg/basic-prelude.git basic-prelude-0.6.1.1/README.md0000644000000000000000000000163112714017574014052 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`. basic-prelude-0.6.1.1/ChangeLog.md0000644000000000000000000000224313056054461014740 0ustar0000000000000000## 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.