packages feed

typelevel-tensor 0.1.1 → 0.2

raw patch · 2 files changed

+22/−27 lines, 2 filesdep −control-monad-failure

Dependencies removed: control-monad-failure

Files

Data/Tensor/TypeLevel.hs view
@@ -25,12 +25,11 @@  import qualified Algebra.Additive as Additive import qualified Algebra.Ring as Ring-import           Control.Monad.Failure import           System.IO.Unsafe import           Text.Read import qualified Text.ParserCombinators.ReadP as P -import           Control.Applicative (Applicative(..), (<$>))+import           Control.Applicative import           Control.Monad hiding     (mapM_, sequence_, forM_, msum, mapM, sequence, forM) import           Data.Foldable@@ -42,7 +41,7 @@      (=<<), foldl, foldl1, foldr, foldr1, and, or, any, all, sum, product,      concat, concatMap, maximum, minimum, elem, notElem) import qualified Prelude as P98-+import qualified Test.QuickCheck.Arbitrary as QC  infixl 9 ! -- | a component operator.@@ -117,17 +116,19 @@  -- | An object that allows component-wise access. class (Traversable v) => Vector v where-  -- | Get a component within f, a context which allows 'Failure'.-  componentF :: (Failure StringException f) =>+  -- | Get a component within f, a context which allows failure.+  componentF :: (Alternative f) =>                 Axis v -- ^the axis of the component you want                 -> v a -- ^the target vector-                -> f a -- ^the component, obtained within a 'Failure' monad+                -> f a -- ^the component, obtained within a failure    -- | Get a component. This computation may result in a runtime error,   -- though, as long as the 'Axis' is generated from library functions   -- such as 'compose', there will be no error.   component :: Axis v -> v a -> a-  component axis vec = unsafePerformFailure $ componentF axis vec+  component axis vec = case componentF axis vec of+    Just x  -> x+    Nothing -> error $ "axis out of bound: " ++ show axis   -- | The dimension of the vector.   dimension :: v a -> Int   -- | Create a 'Vector' from a function that maps@@ -136,13 +137,13 @@  instance Vector Vec where   componentF axis Vec-    = failureString $ "axis out of bound: " ++ show axis+    = empty   dimension _ = 0   compose _ = Vec  instance (Vector v) => Vector ((:~) v) where   componentF (Axis i) vx@(v :~ x)-    | i==dimension vx - 1 = return x+    | i==dimension vx - 1 = pure x     | True                = componentF (Axis i) v   dimension (v :~ _) = 1 + dimension v   compose f = let@@ -172,14 +173,15 @@ -- thus providing unit vectors. class  (Vector v, Ring.C a) => VectorRing v a where   -- | A vector where 'Axis'th component is unity but others are zero.-  unitVectorF :: (Failure StringException f) => Axis v -> f (v a)+  unitVectorF :: (Alternative f) => Axis v -> f (v a)   -- | pure but unsafe version means of obtaining a 'unitVector'   unitVector :: Axis v -> v a-  unitVector = unsafePerformFailure . unitVectorF+  unitVector axis = case unitVectorF axis of+    Just x  -> x+    Nothing -> error $ "axis out of bound: " ++ show axis  instance (Ring.C a) => VectorRing Vec a where-  unitVectorF axis-      = failureString $ "axis out of bound: " ++ show axis+  unitVectorF axis = empty  instance (Ring.C a, VectorRing v a, Additive.C (v a))     => VectorRing ((:~) v) a where@@ -188,10 +190,10 @@       z = Additive.zero       d = dimension z       ret-        | i < 0 || i >= d   = failureString $ "axis out of bound: " ++ show axis-        | i == d-1          = return $ Additive.zero :~ Ring.one-        | 0 <= i && i < d-1 = liftM (:~ Additive.zero) $ unitVectorF (Axis i)-        | True              = return z+        | i < 0 || i >= d   = empty+        | i == d-1          = pure $ Additive.zero :~ Ring.one+        | 0 <= i && i < d-1 = fmap (:~ Additive.zero) $ unitVectorF (Axis i)+        | True              = pure z         -- this last guard never matches, but needed to infer the type of z.  instance (Vector v, P98.Num a) => P98.Num ((:~) v a) where@@ -239,8 +241,3 @@ vec9 x0 x1 x2 x3 x4 x5 x6 x7 x8 = Vec :~ x0 :~ x1 :~ x2 :~ x3 :~ x4 :~ x5 :~ x6 :~ x7 :~ x8 vec10 :: a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> Vec10 a vec10 x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 = Vec :~ x0 :~ x1 :~ x2 :~ x3 :~ x4 :~ x5 :~ x6 :~ x7 :~ x8 :~ x9----- | convert Failure to runtime error-unsafePerformFailure :: IO a -> a-unsafePerformFailure = unsafePerformIO
typelevel-tensor.cabal view
@@ -16,7 +16,7 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented.-Version:             0.1.1+Version:             0.2  -- A short (one-line) description of the package. Synopsis:            Tensors whose ranks and dimensions type-inferred and type-checked.@@ -68,9 +68,8 @@      -- Packages needed in order to build this package.   Build-depends: base            == 4.*,-                 control-monad-failure >= 0.7.0,-                 numeric-prelude >= 0.3-+                 numeric-prelude >= 0.3,+                 QuickCheck >= 2    -- Modules not exported by this package.   -- Other-modules:          @@ -91,7 +90,6 @@     type: exitcode-stdio-1.0     Build-depends: array >= 0.4,                    base            == 4.*                   ,-                   control-monad-failure >= 0.7.0  ,                    numeric-prelude >= 0.3       ,                    test-framework                           ,                    test-framework-quickcheck2               ,