int-cast 0.1.1.0 → 0.1.2.0
raw patch · 3 files changed
+45/−36 lines, 3 filesdep ~QuickCheckdep ~basedep ~natsPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: QuickCheck, base, nats
API changes (from Hackage documentation)
Files
- Data/IntCast.hs +31/−28
- changelog.md +6/−0
- int-cast.cabal +8/−8
Data/IntCast.hs view
@@ -58,6 +58,7 @@ import GHC.TypeLits import Data.Bits import Data.Type.Equality+import Numeric.Natural (Natural) -- | (Kind) Meta-information about integral types. --@@ -79,7 +80,8 @@ -- information about the value range of an integral type. -- -- This module also provides type family instances for the standard--- Haskell 2010 integral types (including "Foreign.C.Types").+-- Haskell 2010 integral types (including "Foreign.C.Types") as well+-- as the 'Natural' type. -- -- Here's a simple example for registering a custom type with the -- "Data.IntCast" facilities:@@ -102,21 +104,22 @@ -- ordering based on the types above. See also 'intCast'. type family IntBaseType a :: IntBaseTypeK -type instance IntBaseType Integer = BigIntTag+type instance IntBaseType Integer = 'BigIntTag+type instance IntBaseType Natural = 'BigWordTag -- Haskell2010 Basic fixed-width Integer Types-type instance IntBaseType Int8 = FixedIntTag 8-type instance IntBaseType Int16 = FixedIntTag 16-type instance IntBaseType Int32 = FixedIntTag 32-type instance IntBaseType Int64 = FixedIntTag 64-type instance IntBaseType Word8 = FixedWordTag 8-type instance IntBaseType Word16 = FixedWordTag 16-type instance IntBaseType Word32 = FixedWordTag 32-type instance IntBaseType Word64 = FixedWordTag 64+type instance IntBaseType Int8 = 'FixedIntTag 8+type instance IntBaseType Int16 = 'FixedIntTag 16+type instance IntBaseType Int32 = 'FixedIntTag 32+type instance IntBaseType Int64 = 'FixedIntTag 64+type instance IntBaseType Word8 = 'FixedWordTag 8+type instance IntBaseType Word16 = 'FixedWordTag 16+type instance IntBaseType Word32 = 'FixedWordTag 32+type instance IntBaseType Word64 = 'FixedWordTag 64 #if defined(WORD_SIZE_IN_BITS)-type instance IntBaseType Int = FixedIntTag WORD_SIZE_IN_BITS-type instance IntBaseType Word = FixedWordTag WORD_SIZE_IN_BITS+type instance IntBaseType Int = {-'-} 'FixedIntTag WORD_SIZE_IN_BITS+type instance IntBaseType Word = {-'-} 'FixedWordTag WORD_SIZE_IN_BITS #else #error Cannot determine bit-size of 'Int'/'Word' type #endif@@ -144,37 +147,37 @@ -- Internal class providing the partial order of (improper) subtype-relations type family IsIntBaseSubType a b :: Bool where -- this relation is reflexive- IsIntBaseSubType a a = True+ IsIntBaseSubType a a = 'True -- Every integer is a subset of 'Integer'- IsIntBaseSubType a BigIntTag = True+ IsIntBaseSubType a 'BigIntTag = 'True -- Even though Haskell2010 doesn't provide naturals, we can use the -- tag 'Nat' to denote such entities- IsIntBaseSubType (FixedWordTag a) BigWordTag = True+ IsIntBaseSubType ('FixedWordTag a) 'BigWordTag = 'True -- sub-type relations between fixed-with types- IsIntBaseSubType (FixedIntTag a) (FixedIntTag b) = a <=? b- IsIntBaseSubType (FixedWordTag a) (FixedWordTag b) = a <=? b- IsIntBaseSubType (FixedWordTag a) (FixedIntTag b) = a+1 <=? b+ IsIntBaseSubType ('FixedIntTag a) ('FixedIntTag b) = a <=? b+ IsIntBaseSubType ('FixedWordTag a) ('FixedWordTag b) = a <=? b+ IsIntBaseSubType ('FixedWordTag a) ('FixedIntTag b) = a+1 <=? b -- everything else is not a sub-type- IsIntBaseSubType a b = False+ IsIntBaseSubType a b = 'False type IsIntSubType a b = IsIntBaseSubType (IntBaseType a) (IntBaseType b) -- Same bit-size predicate type family IsIntBaseTypeIso a b :: Bool where- IsIntBaseTypeIso a a = True- IsIntBaseTypeIso (FixedIntTag n) (FixedWordTag n) = True- IsIntBaseTypeIso (FixedWordTag n) (FixedIntTag n) = True- IsIntBaseTypeIso a b = False+ IsIntBaseTypeIso a a = 'True+ IsIntBaseTypeIso ('FixedIntTag n) ('FixedWordTag n) = 'True+ IsIntBaseTypeIso ('FixedWordTag n) ('FixedIntTag n) = 'True+ IsIntBaseTypeIso a b = 'False type IsIntTypeIso a b = IsIntBaseTypeIso (IntBaseType a) (IntBaseType b) type family IsIntBaseTypeEq (a :: IntBaseTypeK) (b :: IntBaseTypeK) :: Bool where- IsIntBaseTypeEq a a = True- IsIntBaseTypeEq a b = False+ IsIntBaseTypeEq a a = 'True+ IsIntBaseTypeEq a b = 'False type IsIntTypeEq a b = IsIntBaseTypeEq (IntBaseType a) (IntBaseType b) @@ -187,7 +190,7 @@ -- Note: This is just a type-restricted alias of 'fromIntegral' and -- should therefore lead to the same compiled code as if -- 'fromIntegral' had been used instead of 'intCast'.-intCast :: (Integral a, Integral b, IsIntSubType a b ~ True) => a -> b+intCast :: (Integral a, Integral b, IsIntSubType a b ~ 'True) => a -> b intCast = fromIntegral {-# INLINE intCast #-} @@ -200,12 +203,12 @@ -- Note: This is just a type-restricted alias of 'fromIntegral' and -- should therefore lead to the same compiled code as if -- 'fromIntegral' had been used instead of 'intCast'.-intCastIso :: (Integral a, Integral b, IsIntTypeIso a b ~ True) => a -> b+intCastIso :: (Integral a, Integral b, IsIntTypeIso a b ~ 'True) => a -> b intCastIso = fromIntegral {-# INLINE intCastIso #-} -- | Version of 'intCast' restricted to casts between types with same value domain.-intCastEq :: (Integral a, Integral b, IsIntTypeEq a b ~ True) => a -> b+intCastEq :: (Integral a, Integral b, IsIntTypeEq a b ~ 'True) => a -> b intCastEq = fromIntegral {-# INLINE intCastEq #-}
changelog.md view
@@ -1,3 +1,9 @@+## 0.1.2.0++ - Add support for GHC 7.10++ - Add support for `Natural`+ ## 0.1.1.0 * Fix `intCastIso` to be reflexive wrt non-fixed integer types
int-cast.cabal view
@@ -1,5 +1,5 @@ name: int-cast-version: 0.1.1.0+version: 0.1.2.0 synopsis: Checked conversions between integral types homepage: https://github.com/hvr/int-cast bug-reports: https://github.com/hvr/int-cast/issues@@ -19,11 +19,6 @@ type: git location: https://github.com/hvr/int-cast.git -source-repository this- type: git- location: https://github.com/hvr/int-cast.git- tag: 0.1.1.0- library default-language: Haskell2010 other-extensions:@@ -32,7 +27,10 @@ TypeFamilies TypeOperators UndecidableInstances- build-depends: base ==4.7.*+ build-depends: base >=4.7 && <4.9+ if !impl(ghc>=7.10)+ build-depends: nats >=0.1 && <1.1+ exposed-modules: Data.IntCast test-suite int-cast-test@@ -41,4 +39,6 @@ hs-source-dirs: test . main-is: Suite.hs ghc-options: -Wall- build-depends: int-cast, base, QuickCheck ==2.6.*, test-framework ==0.8.*, test-framework-quickcheck2 ==0.3.*, nats ==0.1.*+ build-depends: int-cast, base, QuickCheck ==2.7.*, test-framework ==0.8.*, test-framework-quickcheck2 ==0.3.*+ if !impl(ghc>=7.10)+ build-depends: nats