{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Data.MonadicStreamFunction.Instances.VectorSpace where
import Control.Arrow ((>>^))
import Data.VectorSpace (VectorSpace (..))
import Control.Arrow.Util (constantly, elementwise2)
import Data.MonadicStreamFunction.Core (MSF)
instance (Monad m, VectorSpace v s) => VectorSpace (MSF m a v) s where
zeroVector :: MSF m a v
zeroVector = v -> MSF m a v
forall (a :: * -> * -> *) b c. Arrow a => b -> a c b
constantly v
forall v a. VectorSpace v a => v
zeroVector
s
r *^ :: s -> MSF m a v -> MSF m a v
*^ MSF m a v
msf = MSF m a v
msf MSF m a v -> (v -> v) -> MSF m a v
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ (s
r s -> v -> v
forall v a. VectorSpace v a => a -> v -> v
*^)
MSF m a v
msf ^/ :: MSF m a v -> s -> MSF m a v
^/ s
r = MSF m a v
msf MSF m a v -> (v -> v) -> MSF m a v
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ (v -> s -> v
forall v a. VectorSpace v a => v -> a -> v
^/ s
r)
^+^ :: MSF m a v -> MSF m a v -> MSF m a v
(^+^) = (v -> v -> v) -> MSF m a v -> MSF m a v -> MSF m a v
forall (a :: * -> * -> *) c d e b.
Arrow a =>
(c -> d -> e) -> a b c -> a b d -> a b e
elementwise2 v -> v -> v
forall v a. VectorSpace v a => v -> v -> v
(^+^)
^-^ :: MSF m a v -> MSF m a v -> MSF m a v
(^-^) = (v -> v -> v) -> MSF m a v -> MSF m a v -> MSF m a v
forall (a :: * -> * -> *) c d e b.
Arrow a =>
(c -> d -> e) -> a b c -> a b d -> a b e
elementwise2 v -> v -> v
forall v a. VectorSpace v a => v -> v -> v
(^-^)
negateVector :: MSF m a v -> MSF m a v
negateVector = (MSF m a v -> (v -> v) -> MSF m a v
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ v -> v
forall v a. VectorSpace v a => v -> v
negateVector)