incipit-base 0.1.0.3 → 0.2.0.0
raw patch · 7 files changed
+139/−4 lines, 7 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Incipit.Base: div :: Integral a => a -> a -> a
- Incipit.Base: divMod :: Integral a => a -> a -> (a, a)
- Incipit.Base: mod :: Integral a => a -> a -> a
- Incipit.Base: quot :: Integral a => a -> a -> a
- Incipit.Base: quotRem :: Integral a => a -> a -> (a, a)
- Incipit.Base: rem :: Integral a => a -> a -> a
+ Incipit.Fixed: div' :: Real a => Integral b => a -> a -> Maybe b
+ Incipit.Fixed: divMod' :: Real a => Integral b => a -> a -> Maybe (b, a)
+ Incipit.Fixed: mod' :: Real a => a -> a -> Maybe a
+ Incipit.Integral: div :: Integral a => a -> a -> Maybe a
+ Incipit.Integral: divMod :: Integral a => a -> a -> Maybe (a, a)
+ Incipit.Integral: mod :: Integral a => a -> a -> Maybe a
+ Incipit.Integral: quot :: Integral a => a -> a -> Maybe a
+ Incipit.Integral: quotRem :: Integral a => a -> a -> Maybe (a, a)
+ Incipit.Integral: rem :: Integral a => a -> a -> Maybe a
+ Incipit.Integral: safeOp :: Real a => (a -> a -> b) -> a -> a -> Maybe b
- Incipit.Misc: foldl :: forall b t a. Foldable t => (b -> a -> b) -> b -> t a -> b
+ Incipit.Misc: foldl :: forall t b a. Foldable t => (b -> a -> b) -> b -> t a -> b
Files
- changelog.md +7/−0
- incipit-base.cabal +4/−1
- lib/Incipit/Base.hs +8/−1
- lib/Incipit/Debug.hs +1/−1
- lib/Incipit/Fixed.hs +36/−0
- lib/Incipit/Integral.hs +82/−0
- lib/Incipit/Misc.hs +1/−1
changelog.md view
@@ -0,0 +1,7 @@+# Unreleased++# 0.2.0.0++* Add safe, `Maybe` returning, versions of the methods of `Integral`.+* Hide constructors of effect GADTs.+* Reexport `Data.Text.Lazy.Builder`.
incipit-base.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: incipit-base-version: 0.1.0.3+version: 0.2.0.0 synopsis: A Prelude for Polysemy – Base Reexports description: See <https://hackage.haskell.org/package/incipit-base/docs/Incipit-Prelude.html> category: Prelude@@ -31,6 +31,8 @@ Incipit.Base Incipit.Debug Incipit.Either+ Incipit.Fixed+ Incipit.Integral Incipit.Libraries Incipit.List Incipit.Misc@@ -62,6 +64,7 @@ , Data.Text , Data.Text.IO , Data.Text.Lazy+ , Data.Text.Lazy.Builder , Data.Text.Lazy.IO , Data.Text.Read , Data.Tree
lib/Incipit/Base.hs view
@@ -7,6 +7,7 @@ module Control.Exception, module Control.Monad, module Control.Monad.Fail,+ module Control.Monad.IO.Class, module Data.Bifunctor, module Data.Bits, module Data.Bool,@@ -45,6 +46,8 @@ module GHC.Show, module GHC.Stack, module GHC.TypeLits,+ module Incipit.Fixed,+ module Incipit.Integral, module Numeric.Natural, module System.IO, ) where@@ -83,6 +86,7 @@ (>=>), ) import Control.Monad.Fail (MonadFail (..))+import Control.Monad.IO.Class import Data.Bifunctor (Bifunctor (..)) import Data.Bits (toIntegralSized, xor) import Data.Bool (Bool (..), bool, not, otherwise, (&&), (||))@@ -180,7 +184,7 @@ import GHC.OverloadedLabels (IsLabel (..)) import GHC.Real ( Fractional (..),- Integral (..),+ Integral (toInteger), Ratio, Rational, Real (..),@@ -201,3 +205,6 @@ import GHC.TypeLits hiding (ErrorMessage (Text)) import Numeric.Natural (Natural) import System.IO (FilePath, IO, print, putStr, putStrLn)++import Incipit.Fixed+import Incipit.Integral
lib/Incipit/Debug.hs view
@@ -4,6 +4,7 @@ module Incipit.Debug where import qualified Data.Text as Text+import Data.Text (Text) import GHC.Stack (CallStack, SrcLoc (..), callStack, getCallStack) import System.IO.Unsafe (unsafePerformIO) @@ -21,7 +22,6 @@ ) import Incipit.List (last) import Incipit.String.Conversion (ToString (toString), ToText (toText), show)-import Data.Text (Text) srcLoc :: CallStack -> SrcLoc srcLoc = \case
+ lib/Incipit/Fixed.hs view
@@ -0,0 +1,36 @@+module Incipit.Fixed where++import qualified Data.Fixed as Fixed+import Data.Maybe (Maybe)+import GHC.Real (Integral, Real)++import Incipit.Integral (safeOp)++-- | Generalisation of 'div' to any instance of 'Real'+div' ::+ Real a =>+ Integral b =>+ a ->+ a ->+ Maybe b+div' =+ safeOp Fixed.div'++-- | Generalisation of 'divMod' to any instance of 'Real'+divMod' ::+ Real a =>+ Integral b =>+ a ->+ a ->+ Maybe (b, a)+divMod' =+ safeOp Fixed.divMod'++-- | Generalisation of 'mod' to any instance of 'Real'+mod' ::+ Real a =>+ a ->+ a ->+ Maybe a+mod' =+ safeOp Fixed.mod'
+ lib/Incipit/Integral.hs view
@@ -0,0 +1,82 @@+module Incipit.Integral where++import Data.Maybe (Maybe (Just, Nothing))+import qualified GHC.Real as Real+import GHC.Real (Integral, Real)++safeOp ::+ Real a =>+ (a -> a -> b) ->+ a ->+ a ->+ Maybe b+safeOp op n = \case+ 0 ->+ Nothing+ d ->+ Just (op n d)+{-# inline safeOp #-}++-- | integer division truncated toward zero+quot ::+ Integral a =>+ a ->+ a ->+ Maybe a+quot =+ safeOp Real.quot+{-# inline quot #-}++-- | integer remainder, satisfying+--+-- > (x `quot` y)*y + (x `rem` y) == x+rem ::+ Integral a =>+ a ->+ a ->+ Maybe a+rem =+ safeOp Real.rem+{-# inline rem #-}++-- | integer division truncated toward negative infinity+div ::+ Integral a =>+ a ->+ a ->+ Maybe a+div =+ safeOp Real.div+{-# inline div #-}++-- | integer modulus, satisfying+--+-- > (x `div` y)*y + (x `mod` y) == x+mod ::+ Integral a =>+ a ->+ a ->+ Maybe a+mod =+ safeOp Real.mod+{-# inline mod #-}++-- | simultaneous 'quot' and 'rem'+quotRem ::+ Integral a =>+ a ->+ a ->+ Maybe (a, a)+quotRem =+ safeOp Real.quotRem+{-# inline quotRem #-}++-- | simultaneous 'div' and 'mod'+divMod ::+ Integral a =>+ a ->+ a ->+ Maybe (a, a)+divMod =+ safeOp Real.divMod+{-# inline divMod #-}
lib/Incipit/Misc.hs view
@@ -46,7 +46,7 @@ -- |Default to using the strict version since the lazy one is so controversial. foldl ::- ∀ b t a .+ ∀ t b a . Foldable t => (b -> a -> b) -> b ->