packages feed

linear 1.8.1 → 1.9

raw patch · 12 files changed

+141/−54 lines, 12 filesdep ~base

Dependency ranges changed: base

Files

CHANGELOG.markdown view
@@ -1,3 +1,9 @@+1.9+---+* Added `MonadZip` instances.+* Added `MonadFix` instances.+* Added `Control.Lens.Each.Each` instances+ 1.8.1 ----- * Bugfixed `slerp`
linear.cabal view
@@ -1,6 +1,6 @@ name:          linear category:      Math, Algebra-version:       1.8.1+version:       1.9 license:       BSD3 cabal-version: >= 1.8 license-file:  LICENSE@@ -85,7 +85,6 @@     doctest   >= 0.8 && < 0.10,     filepath  >= 1.3 && < 1.4,     lens,-    linear,     simple-reflect >= 0.3.1  test-suite UnitTests
src/Linear/Affine.hs view
@@ -1,7 +1,6 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE DeriveTraversable #-} {-# LANGUAGE TypeFamilies #-} #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Trustworthy #-}
src/Linear/Instances.hs view
@@ -16,6 +16,8 @@ module Linear.Instances () where  import Control.Applicative+import Control.Monad.Fix+import Control.Monad.Zip import Data.Complex import Data.Foldable import Data.Functor.Bind@@ -62,6 +64,12 @@     a' :+ _  = f a     _  :+ b' = f b   {-# INLINE (>>=) #-}++instance MonadZip Complex where+  mzipWith = liftA2++instance MonadFix Complex where+  mfix f = (let a :+ _ = f a in a) :+ (let _ :+ a = f a in a)  instance Foldable Complex where   foldMap f (a :+ b) = f a `mappend` f b
src/Linear/Plucker.hs view
@@ -46,6 +46,8 @@  import Control.Applicative import Control.Monad (liftM)+import Control.Monad.Fix+import Control.Monad.Zip import Control.Lens hiding (index, (<.>)) import Data.Distributive import Data.Foldable as Foldable@@ -345,15 +347,15 @@ type instance Index (Plucker a) = E Plucker type instance IxValue (Plucker a) = a -#if MIN_VERSION_lens(4,0,0) instance Ixed (Plucker a) where   ix = el-#else-instance Functor f => Ixed f (Plucker a) where-  ix i f = el i (indexed f i)-#endif+  {-# INLINE ix #-} +instance Each (Plucker a) (Plucker b) a b where+  each = traverse+  {-# INLINE each #-} + -- | Valid Plücker coordinates @p@ will have @'squaredError' p '==' 0@ -- -- That said, floating point makes a mockery of this claim, so you may want to use 'nearZero'.@@ -520,3 +522,14 @@        v <- G.basicUnsafeIndexM a (o+4)        u <- G.basicUnsafeIndexM a (o+5)        return (Plucker x y z w v u)++instance MonadZip Plucker where+  mzipWith = liftA2++instance MonadFix Plucker where+  mfix f = Plucker (let Plucker a _ _ _ _ _ = f a in a)+                   (let Plucker _ a _ _ _ _ = f a in a)+                   (let Plucker _ _ a _ _ _ = f a in a)+                   (let Plucker _ _ _ a _ _ = f a in a)+                   (let Plucker _ _ _ _ a _ = f a in a)+                   (let Plucker _ _ _ _ _ a = f a in a)
src/Linear/Quaternion.hs view
@@ -40,6 +40,8 @@  import Control.Applicative import Control.Monad (liftM)+import Control.Monad.Fix+import Control.Monad.Zip import Control.Lens hiding ((<.>)) import Data.Complex (Complex((:+))) import Data.Data@@ -161,14 +163,14 @@ type instance Index (Quaternion a) = E Quaternion type instance IxValue (Quaternion a) = a -#if MIN_VERSION_lens(4,0,0) instance Ixed (Quaternion a) where   ix = el-#else-instance Functor f => Ixed f (Quaternion a) where-  ix i f = el i (indexed f i)-#endif+  {-# INLINE ix #-} +instance Each (Quaternion a) (Quaternion b) a b where+  each = traverse+  {-# INLINE each #-}+ instance Foldable Quaternion where   foldMap f (Quaternion e v) = f e `mappend` foldMap f v   {-# INLINE foldMap #-}@@ -473,7 +475,7 @@ slerp :: RealFloat a => Quaternion a -> Quaternion a -> a -> Quaternion a slerp q p t   | 1.0 - cosphi < 1e-8 = q-  | otherwise           = ((sin ((1-t)*phi) *^ q) + (sin (t*phi)) *^ (f p)) ^/ (sin phi)+  | otherwise           = ((sin ((1-t)*phi) *^ q) + sin (t*phi) *^ f p) ^/ sin phi   where     dqp = dot q p     (cosphi, f) = if dqp < 0 then (-dqp, negate) else (dqp, id)@@ -534,3 +536,12 @@        z <- G.basicUnsafeIndexM v (o+2)        w <- G.basicUnsafeIndexM v (o+3)        return (Quaternion x (V3 y z w))++instance MonadZip Quaternion where+  mzipWith = liftA2++instance MonadFix Quaternion where+  mfix f = Quaternion (let Quaternion a _ = f a in a)+                      (let Quaternion _ (V3 a _ _) = f a in a)+                      (let Quaternion _ (V3 _ a _) = f a in a)+                      (let Quaternion _ (V3 _ _ a) = f a in a)
src/Linear/V.hs view
@@ -2,7 +2,6 @@ {-# LANGUAGE KindSignatures #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE Rank2Types #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE EmptyDataDecls #-}@@ -16,9 +15,11 @@ {-# LANGUAGE Trustworthy #-} {-# LANGUAGE DeriveGeneric #-} #endif-#ifndef MIN_VERSION_lens-#define MIN_VERSION_lens(x,y,z) 1++#ifndef MIN_VERSION_reflection+#define MIN_VERSION_reflection(x,y,z) 1 #endif+ ----------------------------------------------------------------------------- -- | -- Copyright   :  (C) 2012-2013 Edward Kmett,@@ -42,6 +43,8 @@   ) where  import Control.Applicative+import Control.Monad.Fix+import Control.Monad.Zip import Control.Lens as Lens import Data.Distributive import Data.Foldable as Foldable@@ -272,13 +275,17 @@ type instance Index (V n a) = E (V n) type instance IxValue (V n a) = a -#if MIN_VERSION_lens(4,0,0) instance Ixed (V n a) where   ix = el   {-# INLINE ix #-}-#else-instance Functor f => Ixed f (V n a) where-  ix i f = el i (Lens.indexed f i)-  {-# INLINE ix #-}-#endif +instance Dim n => MonadZip (V n) where+  mzip (V as) (V bs) = V $ V.zip as bs+  mzipWith f (V as) (V bs) = V $ V.zipWith f as bs++instance Dim n => MonadFix (V n) where+  mfix f = tabulate $ \r -> let a = index (f a) r in a++instance Each (V n a) (V n b) a b where+  each = traverse+  {-# INLINE each #-}
src/Linear/V0.hs view
@@ -8,9 +8,6 @@ {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE Trustworthy #-} #endif-#ifndef MIN_VERSION_lens-#define MIN_VERSION_lens(x,y,z) 1-#endif ----------------------------------------------------------------------------- -- | -- Copyright   :  (C) 2012-2013 Edward Kmett@@ -28,6 +25,8 @@  import Control.Applicative import Control.Lens+import Control.Monad.Fix+import Control.Monad.Zip import Data.Data import Data.Distributive import Data.Foldable@@ -180,16 +179,14 @@ type instance Index (V0 a) = E V0 type instance IxValue (V0 a) = a -#if MIN_VERSION_lens(4,0,0) instance Ixed (V0 a) where   ix = el   {-# INLINE ix #-}-#else-instance Functor f => Ixed f (V0 a) where-  ix i f = el i (indexed f i)-  {-# INLINE ix #-}-#endif +instance Each (V0 a) (V0 b) a b where+  each = traverse+  {-# INLINE each #-}+ newtype instance U.Vector    (V0 a) = V_V0 Int newtype instance U.MVector s (V0 a) = MV_V0 Int instance U.Unbox (V0 a)@@ -208,3 +205,11 @@   basicLength (V_V0 n) = n   basicUnsafeSlice _ n _ = V_V0 n   basicUnsafeIndexM _ _ = return V0++instance MonadZip V0 where+  mzip V0 V0 = V0+  mzipWith _ V0 V0 = V0+  munzip V0 = (V0, V0)++instance MonadFix V0 where+  mfix _ = V0
src/Linear/V1.hs view
@@ -32,6 +32,8 @@  import Control.Applicative import Control.Monad (liftM)+import Control.Monad.Fix+import Control.Monad.Zip import Control.Lens import Data.Data import Data.Distributive@@ -56,6 +58,11 @@ import qualified Data.Vector.Generic as G import qualified Data.Vector.Unboxed.Base as U +#ifdef HLINT+-- HLint is delusional+{-# ANN module "HLint: ignore Unused LANGUAGE pragma" #-}+#endif+ -- $setup -- >>> import Control.Lens @@ -211,16 +218,14 @@ type instance Index (V1 a) = E V1 type instance IxValue (V1 a) = a -#if MIN_VERSION_lens(4,0,0) instance Ixed (V1 a) where   ix = el   {-# INLINE ix #-}-#else-instance Functor f => Ixed f (V1 a) where-  ix i f = el i (indexed f i)-  {-# INLINE ix #-}-#endif +instance Each (V1 a) (V1 b) a b where+  each f (V1 x) = V1 <$> f x+  {-# INLINE each #-}+ newtype instance U.Vector    (V1 a) = V_V1  (U.Vector    a) newtype instance U.MVector s (V1 a) = MV_V1 (U.MVector s a) instance U.Unbox a => U.Unbox (V1 a)@@ -239,3 +244,11 @@   basicLength (V_V1 v) = G.basicLength v   basicUnsafeSlice m n (V_V1 v) = V_V1 (G.basicUnsafeSlice m n v)   basicUnsafeIndexM (V_V1 v) i = liftM V1 (G.basicUnsafeIndexM v i)++instance MonadZip V1 where+  mzip (V1 a) (V1 b) = V1 (a, b)+  mzipWith f (V1 a) (V1 b) = V1 (f a b)+  munzip (V1 (a,b)) = (V1 a, V1 b)++instance MonadFix V1 where+  mfix f = V1 (let V1 a = f a in a)
src/Linear/V2.hs view
@@ -30,6 +30,8 @@  import Control.Applicative import Control.Monad (liftM)+import Control.Monad.Fix+import Control.Monad.Zip import Control.Lens hiding ((<.>)) import Data.Data import Data.Distributive@@ -264,16 +266,14 @@ type instance Index (V2 a) = E V2 type instance IxValue (V2 a) = a -#if MIN_VERSION_lens(4,0,0) instance Ixed (V2 a) where   ix = el   {-# INLINE ix #-}-#else-instance Functor f => Ixed f (V2 a) where-  ix i f = el i (indexed f i)-  {-# INLINE ix #-}-#endif +instance Each (V2 a) (V2 b) a b where+  each = traverse+  {-# INLINE each #-}+ data instance U.Vector    (V2 a) =  V_V2 !Int (U.Vector    a) data instance U.MVector s (V2 a) = MV_V2 !Int (U.MVector s a) instance U.Unbox a => U.Unbox (V2 a)@@ -303,3 +303,10 @@        x <- G.basicUnsafeIndexM v o        y <- G.basicUnsafeIndexM v (o+1)        return (V2 x y)++instance MonadZip V2 where+  mzipWith = liftA2++instance MonadFix V2 where+  mfix f = V2 (let V2 a _ = f a in a)+              (let V2 _ a = f a in a)
src/Linear/V3.hs view
@@ -30,6 +30,8 @@  import Control.Applicative import Control.Monad (liftM)+import Control.Monad.Fix+import Control.Monad.Zip import Control.Lens hiding ((<.>)) import Data.Data import Data.Distributive@@ -259,14 +261,14 @@ type instance Index (V3 a) = E V3 type instance IxValue (V3 a) = a -#if MIN_VERSION_lens(4,0,0) instance Ixed (V3 a) where   ix = el-#else-instance Functor f => Ixed f (V3 a) where-  ix i f = el i (indexed f i)-#endif+  {-# INLINE ix #-} +instance Each (V3 a) (V3 b) a b where+  each = traverse+  {-# INLINE each #-}+ data instance U.Vector    (V3 a) =  V_V3 !Int (U.Vector    a) data instance U.MVector s (V3 a) = MV_V3 !Int (U.MVector s a) instance U.Unbox a => U.Unbox (V3 a)@@ -299,3 +301,11 @@        y <- G.basicUnsafeIndexM v (o+1)        z <- G.basicUnsafeIndexM v (o+2)        return (V3 x y z)++instance MonadZip V3 where+  mzipWith = liftA2++instance MonadFix V3 where+  mfix f = V3 (let V3 a _ _ = f a in a)+              (let V3 _ a _ = f a in a)+              (let V3 _ _ a = f a in a)
src/Linear/V4.hs view
@@ -31,6 +31,8 @@  import Control.Applicative import Control.Monad (liftM)+import Control.Monad.Fix+import Control.Monad.Zip import Control.Lens hiding ((<.>)) import Data.Data import Data.Distributive@@ -284,14 +286,12 @@ type instance Index (V4 a) = E V4 type instance IxValue (V4 a) = a -#if MIN_VERSION_lens(4,0,0) instance Ixed (V4 a) where   ix = el-#else-instance Functor f => Ixed f (V4 a) where-  ix i f = el i (indexed f i)-#endif +instance Each (V4 a) (V4 b) a b where+  each = traverse+ data instance U.Vector    (V4 a) =  V_V4 !Int (U.Vector    a) data instance U.MVector s (V4 a) = MV_V4 !Int (U.MVector s a) instance U.Unbox a => U.Unbox (V4 a)@@ -327,3 +327,12 @@        z <- G.basicUnsafeIndexM v (o+2)        w <- G.basicUnsafeIndexM v (o+3)        return (V4 x y z w)++instance MonadZip V4 where+  mzipWith = liftA2++instance MonadFix V4 where+  mfix f = V4 (let V4 a _ _ _ = f a in a)+              (let V4 _ a _ _ = f a in a)+              (let V4 _ _ a _ = f a in a)+              (let V4 _ _ _ a = f a in a)