intro 0.8.0.0 → 0.9.0.0
raw patch · 4 files changed
+109/−6 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Intro: fromInteger :: Num a => Integer -> a
- Intro: fromIntegral :: (Integral a, Num b) => a -> b
+ Intro: ($<) :: Contravariant f => f b -> b -> f a
+ Intro: (>$$<) :: Contravariant f => f b -> (a -> b) -> f a
+ Intro: (>$) :: Contravariant f => b -> f b -> f a
+ Intro: (>$<) :: Contravariant f => (a -> b) -> f b -> f a
+ Intro: class Contravariant (f :: Type -> Type)
+ Intro: class ToIntegral a b
+ Intro: contramap :: Contravariant f => (a -> b) -> f b -> f a
+ Intro: fromIntegerUnsafe :: Num a => Integer -> a
+ Intro: fromIntegralUnsafe :: (Integral a, Num b) => a -> b
+ Intro: toIntegral :: (ToIntegral a b, Integral a, Integral b) => a -> b
+ Intro: toIntegralSized :: (Integral a, Integral b, Bits a, Bits b) => a -> Maybe b
Files
- README.md +1/−1
- intro.cabal +3/−2
- src/Intro.hs +26/−3
- src/Intro/ConvertIntegral.hs +79/−0
README.md view
@@ -15,7 +15,7 @@ List of design decisions: -* Keep everything at one place (Actually there are three modules; Intro.Trustworthy is needed for Safe Haskell)+* Keep everything at one place * Conservative extension over the base Prelude * Rely only on common additional libraries * Avoid writing custom functions
intro.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.12 name: intro-version: 0.8.0.0+version: 0.9.0.0 synopsis: Safe and minimal prelude description: Intro is a modern Prelude which provides safe alternatives for most of the partial functions and follows other@@ -22,7 +22,7 @@ copyright: 2016-2017 Daniel Mendler license: MIT license-file: LICENSE-tested-with: GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.1+tested-with: GHC == 8.6.5, GHC == 8.8.1, GHC == 8.10.1 build-type: Simple extra-source-files: README.md@@ -36,6 +36,7 @@ Intro other-modules: Intro.ConvertString+ Intro.ConvertIntegral Intro.Trustworthy hs-source-dirs: src
src/Intro.hs view
@@ -53,6 +53,13 @@ -- * 'sequence' = 'Control.Applicative.sequenceA' -- * 'sequence_' = 'Control.Applicative.sequenceA_' --+-- Integral type conversions are more restricted:+--+-- * 'toIntegral' is a safer, but more restricted version of 'fromIntegral'+-- * 'toIntegerSized' is safe and checked+-- * 'fromIntegralUnsafe' to get the unsafe, overflowing behavior+-- * 'fromIntegerUnsafe' instead of 'fromInteger'+-- -- Unsafe functions are not provided. For example 'read' is replaced by 'readMaybe'. -- The unsafe list functions are replaced by their 'NonEmpty' counterparts. Furthermore '*May' and '*Def' -- functions are exported from the 'safe' package, e.g., 'headMay'.@@ -306,7 +313,9 @@ -- * Numeric type classes -- ** Num- , Prelude.Num((+), (-), (*), negate, abs, signum, fromInteger)+ , Prelude.Num((+), (-), (*), negate, abs, signum+ -- fromInteger+ ) , Prelude.subtract , (Prelude.^) -- partial functions! @@ -316,7 +325,11 @@ -- ** Integral , Prelude.Integral(quot, rem, div, mod, quotRem, divMod, toInteger) -- partial functions!- , Prelude.fromIntegral+ , Intro.ConvertIntegral.ToIntegral(..)+ , Data.Bits.toIntegralSized+ , Intro.ConvertIntegral.fromIntegralUnsafe+ , Intro.ConvertIntegral.fromIntegerUnsafe+ --, Prelude.fromIntegral , Prelude.even , Prelude.odd --, Prelude.gcd@@ -435,6 +448,15 @@ , Control.Applicative.Const(Const, getConst) -- Data.Functor.Const , Data.Functor.Identity.Identity(Identity, runIdentity) + -- ** Contravariant+ , Data.Functor.Contravariant.Contravariant(+ (>$),+ contramap+ )+ , (Data.Functor.Contravariant.$<)+ , (Data.Functor.Contravariant.>$<)+ , (Data.Functor.Contravariant.>$$<)+ -- ** Foldable , Data.Foldable.Foldable(elem, fold, foldMap, foldr, foldr',@@ -661,6 +683,7 @@ import Data.Semigroup (Semigroup((<>))) import Data.String (IsString(fromString), String) import Data.Text (Text)+import Intro.ConvertIntegral import Intro.ConvertString import Intro.Trustworthy import System.IO (FilePath)@@ -694,6 +717,7 @@ import qualified Data.Functor import qualified Data.Functor.Classes import qualified Data.Functor.Identity+import qualified Data.Functor.Contravariant import qualified Data.HashMap.Strict import qualified Data.HashSet import qualified Data.Hashable@@ -930,4 +954,3 @@ fail :: Control.Monad.Fail.MonadFail m => Text -> m a fail = Control.Monad.Fail.fail . convertString {-# INLINE fail #-}-
+ src/Intro/ConvertIntegral.hs view
@@ -0,0 +1,79 @@+-----------------------------------------------------------------------------+-- |+-- Module : Intro.ConvertInt+-- Copyright : (c) Daniel Mendler 2020+-- License : MIT+--+-- Maintainer : mail@daniel-mendler.de+-- Stability : experimental+-- Portability : portable+--+-- Integer conversion+--+-----------------------------------------------------------------------------++{-# LANGUAGE Safe #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE DefaultSignatures #-}++module Intro.ConvertIntegral (+ ToIntegral(..)+ , fromIntegralUnsafe+ , fromIntegerUnsafe+) where++import Data.Int+import Data.Word++class ToIntegral a b where+ toIntegral :: a -> b+ default toIntegral :: (Integral a, Integral b) => a -> b+ toIntegral = fromIntegral+ {-# INLINE toIntegral #-}++instance ToIntegral Word8 Int16+instance ToIntegral Word8 Int32+instance ToIntegral Word8 Int64+instance ToIntegral Word8 Int+instance ToIntegral Word16 Int32+instance ToIntegral Word16 Int64+instance ToIntegral Word16 Int+instance ToIntegral Word32 Int64++instance ToIntegral Word8 Word16+instance ToIntegral Word8 Word32+instance ToIntegral Word8 Word64+instance ToIntegral Word8 Word+instance ToIntegral Word16 Word32+instance ToIntegral Word16 Word64+instance ToIntegral Word16 Word+instance ToIntegral Word32 Word64++instance ToIntegral Int8 Integer+instance ToIntegral Int16 Integer+instance ToIntegral Int32 Integer+instance ToIntegral Int64 Integer+instance ToIntegral Int Integer++instance ToIntegral Word8 Integer+instance ToIntegral Word16 Integer+instance ToIntegral Word32 Integer+instance ToIntegral Word64 Integer+instance ToIntegral Word Integer++instance ToIntegral Int8 Int16+instance ToIntegral Int8 Int32+instance ToIntegral Int8 Int64+instance ToIntegral Int8 Int+instance ToIntegral Int16 Int32+instance ToIntegral Int16 Int64+instance ToIntegral Int16 Int+instance ToIntegral Int32 Int64++fromIntegralUnsafe :: (Integral a, Num b) => a -> b+fromIntegralUnsafe = fromIntegral+{-# INLINE fromIntegralUnsafe #-}++fromIntegerUnsafe :: Num a => Integer -> a+fromIntegerUnsafe = fromInteger+{-# INLINE fromIntegerUnsafe #-}