#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702
#endif
module Linear.V1
( V1(..)
, R1(..)
) where
import Control.Applicative
import Data.Data
import Data.Distributive
import Data.Foldable
import Data.Functor.Identity (Identity(..))
import Data.Traversable
import Data.Semigroup.Foldable
import Data.Semigroup.Traversable
import Data.Functor.Bind
import Foreign.Storable (Storable)
import GHC.Arr (Ix(..))
import Linear.Core
import Linear.Metric
import Linear.Epsilon
import Linear.Vector
import Prelude hiding (sum)
newtype V1 a = V1 a
deriving (Eq,Ord,Show,Read,Data,Typeable,
Functor,Foldable,Traversable,
Epsilon,Storable)
instance Foldable1 V1 where
foldMap1 f (V1 a) = f a
instance Traversable1 V1 where
traverse1 f (V1 a) = V1 <$> f a
instance Apply V1 where
V1 f <.> V1 x = V1 (f x)
instance Applicative V1 where
pure = V1
V1 f <*> V1 x = V1 (f x)
instance Additive V1 where
zero = pure 0
liftU2 = liftA2
liftI2 = liftA2
instance Bind V1 where
V1 a >>- f = f a
instance Monad V1 where
return = V1
V1 a >>= f = f a
instance Num a => Num (V1 a) where
(+) = liftA2 (+)
() = liftA2 ()
(*) = liftA2 (*)
negate = fmap negate
abs = fmap abs
signum = fmap signum
fromInteger = pure . fromInteger
instance Fractional a => Fractional (V1 a) where
recip = fmap recip
(/) = liftA2 (/)
fromRational = pure . fromRational
instance Metric V1 where
dot (V1 a) (V1 b) = a * b
class R1 t where
_x :: Functor f => (a -> f a) -> t a -> f (t a)
instance R1 V1 where
_x f (V1 a) = V1 <$> f a
instance R1 Identity where
_x f (Identity a) = Identity <$> f a
instance Core V1 where
core f = V1 (f _x)
instance Distributive V1 where
distribute f = V1 (fmap (\(V1 x) -> x) f)
instance Ix a => Ix (V1 a) where
range (V1 l1, V1 u1) =
[ V1 i1 | i1 <- range (l1,u1) ]
unsafeIndex (V1 l1,V1 u1) (V1 i1) = unsafeIndex (l1,u1) i1
inRange (V1 l1,V1 u1) (V1 i1) = inRange (l1,u1) i1