type-level-numbers 0.1.1.0 → 0.1.1.1
raw patch · 7 files changed
+146/−20 lines, 7 filesdep +type-level-numbersdep ~basedep ~template-haskell
Dependencies added: type-level-numbers
Dependency ranges changed: base, template-haskell
Files
- ChangeLog +24/−0
- TypeLevel/Number/Int.hs +4/−1
- TypeLevel/Number/Nat.hs +2/−1
- test/TestNat.hs +60/−0
- test/int.hs +16/−0
- test/nat.hs +16/−0
- type-level-numbers.cabal +24/−18
+ ChangeLog view
@@ -0,0 +1,24 @@+Changes in 0.1.1.1++ * Type level addition is fixed for GHC 7.6++ * Test suite added to cabal file++ +Changes in 0.1.1.0++ * withNat, withInt, SomeNat and SomeInt added.+++Changes in 0.1.0.3++ * Fix build for GHC 7.4+++Changes in 0.1.0.2:++ * Fix URL in cabal file++Changes in 0.1.0.1:++ * Workaround for GHC bug #4364 (Build failure on GHC 7.0)
TypeLevel/Number/Int.hs view
@@ -145,7 +145,10 @@ type family AddBit n :: * type instance AddBit ZZ = ZZ-type instance AddBit (a b) = D0 (a b)+type instance AddBit (Dn a) = D0 (Dn a)+type instance AddBit (D0 a) = D0 (D0 a)+type instance AddBit (D1 a) = D0 (D1 a)+ type instance Normalized ZZ = ZZ type instance Normalized (Dn n) = Dn (Normalized n)
TypeLevel/Number/Nat.hs view
@@ -198,7 +198,8 @@ -- equal to zero. Actual normalization is done here. type family Add0Bit n :: * type instance Add0Bit Z = Z-type instance Add0Bit (a b) = (O (a b))+type instance Add0Bit (O n) = (O (O n))+type instance Add0Bit (I n) = (O (I n)) type instance Normalized Z = Z type instance Normalized (I n) = I (Normalized n)
+ test/TestNat.hs view
@@ -0,0 +1,60 @@+{-# LANGUAGE TemplateHaskell #-}+module TestNat where+ +import Language.Haskell.TH+import Text.Printf++import TypeLevel.Number.Nat as N+import TypeLevel.Number.Int as I+++----------------------------------------------------------------+-- Natural numbers++testAdd :: Integer -> Integer -> ExpQ+testAdd n m = + [| let flag = (n+m) == (N.toInt $ addN (undefined :: $(natT n)) (undefined :: $(natT m)) :: Integer)+ in test "+" n m flag+ |]++testSub :: Integer -> Integer -> ExpQ+testSub n m = + [| let flag = (n-m) == (N.toInt $ subN (undefined :: $(natT n)) (undefined :: $(natT m)) :: Integer)+ in test "-" n m flag+ |]++testMul :: Integer -> Integer -> ExpQ+testMul n m = + [| let flag = (n*m) == (N.toInt $ mulN (undefined :: $(natT n)) (undefined :: $(natT m)) :: Integer)+ in test "*" n m flag+ |]++----------------------------------------------------------------+-- Integer numbers++testAddZ :: Integer -> Integer -> ExpQ+testAddZ n m = + [| let flag = (n+m) == (I.toInt $ addN (undefined :: $(intT n)) (undefined :: $(intT m)) :: Integer)+ in test "+" n m flag+ |]++testSubZ :: Integer -> Integer -> ExpQ+testSubZ n m = + [| let flag = (n-m) == (I.toInt $ subN (undefined :: $(intT n)) (undefined :: $(intT m)) :: Integer)+ in test "-" n m flag+ |]++testMulZ :: Integer -> Integer -> ExpQ+testMulZ n m = + [| let flag = (n*m) == (I.toInt $ mulN (undefined :: $(intT n)) (undefined :: $(intT m)) :: Integer)+ in test "*" n m flag+ |]++test :: String -> Integer -> Integer -> Bool -> IO Bool+test op n m flag = do+ _ <- printf "%3i %s %3i : %s\n" n op m (text flag)+ return flag+ where+ text :: Bool -> String+ text True = "OK"+ text False = "Failed"
+ test/int.hs view
@@ -0,0 +1,16 @@+{-# LANGUAGE TemplateHaskell #-}+import Control.Applicative+import Language.Haskell.TH+import System.Exit++import TestNat+++main :: IO ()+main = do+ plus <- sequence $(listE (testAddZ <$> [-9..9] <*> [-9..9]))+ minus <- sequence $(listE (testSubZ <$> [-9..9] <*> [-9..9]))+ mult <- sequence $(listE (testMulZ <$> [-9..9] <*> [-9..9]))+ case and $ plus ++ minus ++ mult of+ True -> exitSuccess+ False -> exitFailure
+ test/nat.hs view
@@ -0,0 +1,16 @@+{-# LANGUAGE TemplateHaskell #-}+import Control.Applicative+import Language.Haskell.TH+import System.Exit++import TestNat+++main :: IO ()+main = do+ plus <- sequence $(listE (testAdd <$> [0..8] <*> [0..8]))+ minus <- sequence $(listE [testSub n m | m <- [0..8], n <- [m..8]])+ mult <- sequence $(listE (testMul <$> [0..8] <*> [0..8]))+ case and $ plus ++ minus ++ mult of+ True -> exitSuccess+ False -> exitFailure
type-level-numbers.cabal view
@@ -1,5 +1,5 @@ Name: type-level-numbers-Version: 0.1.1.0+Version: 0.1.1.1 Synopsis: Type level numbers implemented using type families. Description:@@ -21,24 +21,8 @@ . So far comparison of numbers, subtraction and multiplication of numbers are supported.- .- Changes in 0.1.1.0- .- * @withNat@, @withInt@, @SomeNat and @SomeInt@ added.- .- Changes in 0.1.0.3- .- * Fix build for GHC 7.4- .- Changes in 0.1.0.2:- .- * Fix URL in cabal file- .- Changes in 0.1.0.1:- .- * Workaround for GHC bug #4364 (Build failure on GHC 7.0) -Cabal-Version: >= 1.6+Cabal-Version: >= 1.8 License: BSD3 License-File: LICENSE Bug-reports: https://github.com/bos/statistics/issues@@ -47,6 +31,8 @@ Homepage: Category: Type System Build-Type: Simple+extra-source-files:+ ChangeLog source-repository head type: hg@@ -70,3 +56,23 @@ TypeLevel.Number.Nat.TH TypeLevel.Number.Int.Types TypeLevel.Util++test-suite test-nat+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ main-is: nat.hs+ other-modules: TestNat+ build-depends:+ base,+ template-haskell,+ type-level-numbers++test-suite test-int+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ main-is: int.hs+ other-modules: TestNat+ build-depends:+ base,+ template-haskell,+ type-level-numbers