{-# OPTIONS_GHC -fno-warn-orphans #-}
-- |
-- Copyright  : (c) Ivan Perez and Manuel Baerenz, 2016
-- License    : BSD3
-- Maintainer : ivan.perez@keera.co.uk
--
-- Number instances for 'MSF's that produce numbers. This allows you to use
-- numeric operators with 'MSF's that output numbers, for example, you can
-- write:
--
-- @
-- msf1 :: MSF Input Double -- defined however you want
-- msf2 :: MSF Input Double -- defined however you want
-- msf3 :: MSF Input Double
-- msf3 = msf1 + msf2
-- @
--
-- instead of
--
-- @
-- msf3 = (msf1 &&& msf2) >>> arr (uncurry (+))
-- @
--
-- Instances are provided for the type classes 'Num', 'Fractional' and
-- 'Floating'.
module Data.MonadicStreamFunction.Instances.Num where

-- Internal imports
import Control.Arrow.Util              (constantly, elementwise, elementwise2)
import Data.MonadicStreamFunction.Core (MSF)

-- | 'Num' instance for 'MSF's.
instance (Monad m, Num b) => Num (MSF m a b) where
  + :: MSF m a b -> MSF m a b -> MSF m a b
(+)         = forall (a :: * -> * -> *) c d e b.
Arrow a =>
(c -> d -> e) -> a b c -> a b d -> a b e
elementwise2 forall a. Num a => a -> a -> a
(+)
  (-)         = forall (a :: * -> * -> *) c d e b.
Arrow a =>
(c -> d -> e) -> a b c -> a b d -> a b e
elementwise2 (-)
  * :: MSF m a b -> MSF m a b -> MSF m a b
(*)         = forall (a :: * -> * -> *) c d e b.
Arrow a =>
(c -> d -> e) -> a b c -> a b d -> a b e
elementwise2 forall a. Num a => a -> a -> a
(*)
  abs :: MSF m a b -> MSF m a b
abs         = forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
elementwise forall a. Num a => a -> a
abs
  signum :: MSF m a b -> MSF m a b
signum      = forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
elementwise forall a. Num a => a -> a
signum
  negate :: MSF m a b -> MSF m a b
negate      = forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
elementwise forall a. Num a => a -> a
negate
  fromInteger :: Integer -> MSF m a b
fromInteger = forall (a :: * -> * -> *) b c. Arrow a => b -> a c b
constantly forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Num a => Integer -> a
fromInteger

-- | 'Fractional' instance for 'MSF's.
instance (Monad m, Fractional b) => Fractional (MSF m a b) where
  fromRational :: Rational -> MSF m a b
fromRational = forall (a :: * -> * -> *) b c. Arrow a => b -> a c b
constantly forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Fractional a => Rational -> a
fromRational
  / :: MSF m a b -> MSF m a b -> MSF m a b
(/)          = forall (a :: * -> * -> *) c d e b.
Arrow a =>
(c -> d -> e) -> a b c -> a b d -> a b e
elementwise2 forall a. Fractional a => a -> a -> a
(/)
  recip :: MSF m a b -> MSF m a b
recip        = forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
elementwise forall a. Fractional a => a -> a
recip

-- | 'Floating' instance for 'MSF's.
instance (Monad m, Floating b) => Floating (MSF m a b) where
  pi :: MSF m a b
pi      = forall (a :: * -> * -> *) b c. Arrow a => b -> a c b
constantly   forall a. Floating a => a
pi
  exp :: MSF m a b -> MSF m a b
exp     = forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
elementwise  forall a. Floating a => a -> a
exp
  log :: MSF m a b -> MSF m a b
log     = forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
elementwise  forall a. Floating a => a -> a
log
  sqrt :: MSF m a b -> MSF m a b
sqrt    = forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
elementwise  forall a. Floating a => a -> a
sqrt
  ** :: MSF m a b -> MSF m a b -> MSF m a b
(**)    = forall (a :: * -> * -> *) c d e b.
Arrow a =>
(c -> d -> e) -> a b c -> a b d -> a b e
elementwise2 forall a. Floating a => a -> a -> a
(**)
  logBase :: MSF m a b -> MSF m a b -> MSF m a b
logBase = forall (a :: * -> * -> *) c d e b.
Arrow a =>
(c -> d -> e) -> a b c -> a b d -> a b e
elementwise2 forall a. Floating a => a -> a -> a
logBase
  sin :: MSF m a b -> MSF m a b
sin     = forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
elementwise  forall a. Floating a => a -> a
sin
  cos :: MSF m a b -> MSF m a b
cos     = forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
elementwise  forall a. Floating a => a -> a
cos
  tan :: MSF m a b -> MSF m a b
tan     = forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
elementwise  forall a. Floating a => a -> a
tan
  asin :: MSF m a b -> MSF m a b
asin    = forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
elementwise  forall a. Floating a => a -> a
asin
  acos :: MSF m a b -> MSF m a b
acos    = forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
elementwise  forall a. Floating a => a -> a
acos
  atan :: MSF m a b -> MSF m a b
atan    = forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
elementwise  forall a. Floating a => a -> a
atan
  sinh :: MSF m a b -> MSF m a b
sinh    = forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
elementwise  forall a. Floating a => a -> a
sinh
  cosh :: MSF m a b -> MSF m a b
cosh    = forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
elementwise  forall a. Floating a => a -> a
cosh
  tanh :: MSF m a b -> MSF m a b
tanh    = forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
elementwise  forall a. Floating a => a -> a
tanh
  asinh :: MSF m a b -> MSF m a b
asinh   = forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
elementwise  forall a. Floating a => a -> a
asinh
  acosh :: MSF m a b -> MSF m a b
acosh   = forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
elementwise  forall a. Floating a => a -> a
acosh
  atanh :: MSF m a b -> MSF m a b
atanh   = forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
elementwise  forall a. Floating a => a -> a
atanh