packages feed

numtype-tf 0.1 → 0.1.1

raw patch · 3 files changed

+16/−12 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Numeric.NumType.TF: instance Typeable Z
+ Numeric.NumType.TF: instance Typeable1 N
+ Numeric.NumType.TF: instance Typeable1 S

Files

Numeric/NumType/TF.lhs view
@@ -12,6 +12,7 @@ >            , EmptyDataDecls >            , FlexibleInstances >            , ScopedTypeVariables+>            , DeriveDataTypeable > #-}  @@ -75,6 +76,7 @@  > import Prelude hiding ((*), (/), (+), (-), negate) > import qualified Prelude ((+), negate)+> import Data.Typeable (Typeable)  Use the same fixity for operators as the Prelude. @@ -133,20 +135,20 @@ 'Z' corresponds to HList's 'HZero'.  > -- | Type level zero.-> data Z+> data Z deriving Typeable  Next we define the "successor" type, here called 'S' (corresponding to HList's 'HSucc').  > -- | Successor type for building type level natural numbers.-> data S n+> data S n deriving Typeable  Finally we define the "negation" type used to represent negative numbers.  > -- | Negation type, used to represent negative numbers by negating > -- type level naturals.-> data N n+> data N n deriving Typeable  The 'NumTypeI' instances restrict how 'Z', 'S', and 'N' may be combined to assemble 'NumType's, and the type synonym declarations demonstrate@@ -210,7 +212,7 @@ > type instance Add (S n) n' = Add n (Succ n') > type instance Add (N n) n' = Add (Succ (N n)) (Pred n') -Substitution is defined trivially with addition and negation.+Subtraction is defined trivially with addition and negation.  > type instance Sub a b = Add a (Negate b) @@ -243,12 +245,14 @@ instead of overflowing the context stack (more confusing).  > type family DivP n m            -- n / m.-> type instance DivP Z (S n) = Z  -- Trivially. -The recursive instance for division is quite complex and in fact I-do not recall how I derived it. But it works (I promise!).+The instances for division is based on the identities: -> type instance DivP (S n) (S n') = S (DivP (Pred (Sub (S n) n')) (S n'))  -- Oh my!+    0 / y = 0,               for y >= 1.+    x / y = (x - y) / y + 1, for x >= y >= 1.++> type instance DivP Z (S n) = Z  -- Trivially.+> type instance DivP (S n) (S m) = S (DivP (Sub (S n) (S m)) (S m))  -- Oh my!  Now we can generalize division to negative numbers too, building on top of 'DivP'. A trivial but tedious exercise.
Numeric/NumType/TFTests.hs view
@@ -11,7 +11,7 @@ -- Compares a type level unary function with a value level unary function -- by converting 'NumType' to 'Integral'. This assumes that the 'toIntegral' -- function is solid.-unaryTest :: (NumType n, NumType n', Num a)+unaryTest :: (NumType n, NumType n', Num a, Eq a, Show a)           => (n -> n') -> (a -> a) -> n -> Test unaryTest f f' x = TestCase $ assertEqual     "Unary function Integral equivalence"@@ -20,7 +20,7 @@ -- Compares a type level binary function with a value level binary function -- by converting 'NumType' to 'Integral'. This assumes that the 'toIntegral' -- function is solid.-binaryTest :: (NumType n, NumType n', NumType n'', Num a)+binaryTest :: (NumType n, NumType n', NumType n'', Num a, Eq a, Show a)            => (n -> n' -> n'') -> (a -> a -> a) -> n -> n' -> Test binaryTest f f' x y = TestCase $ assertEqual     "Binary function Integral equivalence"
numtype-tf.cabal view
@@ -1,11 +1,11 @@ Name:                numtype-tf-Version:             0.1+Version:             0.1.1 License:             BSD3 License-File:        LICENSE Copyright:           Bjorn Buckwalter 2012 Author:              Bjorn Buckwalter Maintainer:          bjorn.buckwalter@gmail.com-Stability:           stable+Stability:           experimental Homepage:            http://dimensional.googlecode.com/ Synopsis:            Type-level (low cardinality) integers, implemented                      using type families.