lean-peano 1.0.1.0 → 1.0.2.0
raw patch · 3 files changed
+28/−29 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- lean-peano.cabal +4/−3
- src/Numeric/Peano.hs +21/−22
- src/Numeric/Peano/Typelevel.hs +3/−4
lean-peano.cabal view
@@ -1,14 +1,15 @@-cabal-version: >= 1.12+cabal-version: 1.12 name: lean-peano-version: 1.0.1.0-synopsis: A maximally lazy, simple implementation of the Peano numbers with minimal dependencies+version: 1.0.2.0+synopsis: A maximally lazy, simple implementation of the Peano numbers with minimal dependencies. description: Please see the README on GitHub at <https://github.com/oisdk/lean-peano#readme> homepage: https://github.com/oisdk/lean-peano#readme bug-reports: https://github.com/oisdk/lean-peano/issues author: Donnacha Oisín Kidney maintainer: mail@doisinkidney.com copyright: 2020 Donnacha Oisín Kidney+category: Numeric license: MIT license-file: LICENSE build-type: Custom
src/Numeric/Peano.hs view
@@ -1,6 +1,6 @@-{-# LANGUAGE BangPatterns #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE DeriveGeneric #-} -- | Peano numerals. Effort is made to make them as efficient as -- possible, and as lazy as possible, but they are many orders of@@ -31,12 +31,12 @@ -- False module Numeric.Peano where -import Data.List (unfoldr)+import Data.List (unfoldr) -import Control.DeepSeq (NFData (rnf))+import Control.DeepSeq (NFData (rnf)) -import Data.Data (Data, Typeable)-import GHC.Generics (Generic)+import Data.Data (Data, Typeable)+import GHC.Generics (Generic) import Numeric.Natural @@ -84,7 +84,7 @@ foldlNat' :: (a -> a) -> a -> Nat -> a foldlNat' f = go where- go !b Z = b+ go !b Z = b go !b (S n) = go (f b) n {-# INLINE foldlNat' #-} @@ -96,8 +96,7 @@ compare (S _) Z = GT Z <= _ = True- S _ <= Z = False- S n <= S m = n <= m+ S n <= m = n < m _ < Z = False n < S m = n <= m@@ -105,12 +104,12 @@ (>=) = flip (<=) (>) = flip (<) - min Z _ = Z- min _ Z = Z+ min Z _ = Z+ min _ Z = Z min (S n) (S m) = S (min n m) - max Z m = m- max n Z = n+ max Z m = m+ max n Z = n max (S n) (S m) = S (max n m) -- | Subtraction stops at zero.@@ -120,7 +119,7 @@ n + m = foldrNat S m n n * m = foldrNat (m+) Z n abs = id- signum Z = Z+ signum Z = Z signum (S _) = S Z fromInteger n | n < 0 = error "cannot convert negative integers to Peano numbers"@@ -176,7 +175,7 @@ instance Enum Nat where succ = S pred (S n) = n- pred Z = error "pred called on zero nat"+ pred Z = error "pred called on zero nat" fromEnum = foldlNat' succ 0 toEnum m | m < 0 = error "cannot convert negative number to Peano"@@ -187,22 +186,22 @@ enumFrom = iterate S enumFromTo n m = unfoldr f (n, S m - n) where- f (_,Z) = Nothing+ f (_,Z) = Nothing f (e,S l) = Just (e, (S e, l)) enumFromThen n m = iterate t n where- ts Z mm = (+) mm+ ts Z mm = (+) mm ts (S nn) (S mm) = ts nn mm- ts nn Z = subtract nn+ ts nn Z = subtract nn t = ts n m enumFromThenTo n m t = unfoldr f (n, jm) where ts (S nn) (S mm) = ts nn mm- ts Z mm = (S t - n, (+) mm, mm)- ts nn Z = (S n - t, subtract nn, nn)+ ts Z mm = (S t - n, (+) mm, mm)+ ts nn Z = (S n - t, subtract nn, nn) (jm,tf,tt) = ts n m td = subtract tt- f (_,Z) = Nothing+ f (_,Z) = Nothing f (e,l@(S _)) = Just (e, (tf e, td l))
src/Numeric/Peano/Typelevel.hs view
@@ -54,13 +54,12 @@ -- | '<=' on type-level naturals. type family (<=) (n :: Nat) (m :: Nat) :: Bool where- Z <= _ = True- S _ <= Z = False- S n <= S m = n <= m+ Z <= _ = True+ S n <= m = n < m -- | '<' on type-level naturals. type family (<) (n :: Nat) (m :: Nat) :: Bool where- _ < Z = False+ _ < Z = False n < S m = n <= m -- | The minimum of two type-level naturals.