{-# LANGUAGE DeriveDataTypeable   #-}
{-# LANGUAGE DeriveFoldable       #-}
{-# LANGUAGE DeriveFunctor        #-}
{-# LANGUAGE DeriveGeneric        #-}
{-# LANGUAGE DeriveTraversable    #-}
{-# LANGUAGE FlexibleContexts     #-}
{-# LANGUAGE ScopedTypeVariables  #-}
{-# LANGUAGE TypeApplications     #-}
{-# LANGUAGE UndecidableInstances #-}

-- |
-- Module      : Numeric.OneLiner
-- Description : Derived methods for numeric typeclasses
-- Copyright   : (c) Justin Le 2021
-- License     : BSD-3
-- Maintainer  : justin@jle.im
-- Stability   : unstable
-- Portability : portable
--
-- Derived methods for numeric typeclasses, using "Generics.OneLiner" and
-- "GHC.Generics".
--
-- Can be used for any types (deriving 'Generic') made with a single
-- constructor, where every field is an instance of 'Num' (or 'Fractional'
-- or 'Floating', depending on the function).
--
-- Also includes a newtype wrapper that imbues any such data type with an
-- instant 'Num' (and 'Fractional' and 'Floating') instance, which can one
-- day be used with /DerivingVia/ syntax to derive instances automatically.
--

module Numeric.OneLiner (
  -- * Newtype wrapper
    GNum(..)
  -- * Generics-derived methods
  -- $num
  -- ** Num
  , gPlus
  , gMinus
  , gTimes
  , gNegate
  , gAbs
  , gSignum
  , gFromInteger
  -- ** Fractional
  , gDivide
  , gRecip
  , gFromRational
  -- ** Floating
  , gPi
  , gExp
  , gLog
  , gSqrt
  , gPower
  , gLogBase
  , gSin
  , gCos
  , gTan
  , gAsin
  , gAcos
  , gAtan
  , gSinh
  , gCosh
  , gTanh
  , gAsinh
  , gAcosh
  , gAtanh
  ) where

import           Data.Coerce
import           Data.Data
import           GHC.Generics
import           Generics.OneLiner

-- | If @a@ is a data type with a single constructor whose fields are all
-- instances of 'Num', then @'GNum' a@ has a 'Num' instance.
--
-- If @a@ is a data type with a single constructor whose fields are all
-- instances of 'Fractional', then @'GNum' a@ has a 'Fractional' instance.
--
-- If @a@ is a data type with a single constructor whose fields are all
-- instances of 'Floating', then @'GNum' a@ has a 'Floating' instance.
--
-- Will one day be able to be used with /DerivingVia/ syntax, to derive
-- instances automatically.
--
newtype GNum a = GNum { GNum a -> a
getGNum :: a }
  deriving (GNum a -> GNum a -> Bool
(GNum a -> GNum a -> Bool)
-> (GNum a -> GNum a -> Bool) -> Eq (GNum a)
forall a. Eq a => GNum a -> GNum a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GNum a -> GNum a -> Bool
$c/= :: forall a. Eq a => GNum a -> GNum a -> Bool
== :: GNum a -> GNum a -> Bool
$c== :: forall a. Eq a => GNum a -> GNum a -> Bool
Eq, Eq (GNum a)
Eq (GNum a)
-> (GNum a -> GNum a -> Ordering)
-> (GNum a -> GNum a -> Bool)
-> (GNum a -> GNum a -> Bool)
-> (GNum a -> GNum a -> Bool)
-> (GNum a -> GNum a -> Bool)
-> (GNum a -> GNum a -> GNum a)
-> (GNum a -> GNum a -> GNum a)
-> Ord (GNum a)
GNum a -> GNum a -> Bool
GNum a -> GNum a -> Ordering
GNum a -> GNum a -> GNum a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (GNum a)
forall a. Ord a => GNum a -> GNum a -> Bool
forall a. Ord a => GNum a -> GNum a -> Ordering
forall a. Ord a => GNum a -> GNum a -> GNum a
min :: GNum a -> GNum a -> GNum a
$cmin :: forall a. Ord a => GNum a -> GNum a -> GNum a
max :: GNum a -> GNum a -> GNum a
$cmax :: forall a. Ord a => GNum a -> GNum a -> GNum a
>= :: GNum a -> GNum a -> Bool
$c>= :: forall a. Ord a => GNum a -> GNum a -> Bool
> :: GNum a -> GNum a -> Bool
$c> :: forall a. Ord a => GNum a -> GNum a -> Bool
<= :: GNum a -> GNum a -> Bool
$c<= :: forall a. Ord a => GNum a -> GNum a -> Bool
< :: GNum a -> GNum a -> Bool
$c< :: forall a. Ord a => GNum a -> GNum a -> Bool
compare :: GNum a -> GNum a -> Ordering
$ccompare :: forall a. Ord a => GNum a -> GNum a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (GNum a)
Ord, Int -> GNum a -> ShowS
[GNum a] -> ShowS
GNum a -> String
(Int -> GNum a -> ShowS)
-> (GNum a -> String) -> ([GNum a] -> ShowS) -> Show (GNum a)
forall a. Show a => Int -> GNum a -> ShowS
forall a. Show a => [GNum a] -> ShowS
forall a. Show a => GNum a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GNum a] -> ShowS
$cshowList :: forall a. Show a => [GNum a] -> ShowS
show :: GNum a -> String
$cshow :: forall a. Show a => GNum a -> String
showsPrec :: Int -> GNum a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> GNum a -> ShowS
Show, ReadPrec [GNum a]
ReadPrec (GNum a)
Int -> ReadS (GNum a)
ReadS [GNum a]
(Int -> ReadS (GNum a))
-> ReadS [GNum a]
-> ReadPrec (GNum a)
-> ReadPrec [GNum a]
-> Read (GNum a)
forall a. Read a => ReadPrec [GNum a]
forall a. Read a => ReadPrec (GNum a)
forall a. Read a => Int -> ReadS (GNum a)
forall a. Read a => ReadS [GNum a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GNum a]
$creadListPrec :: forall a. Read a => ReadPrec [GNum a]
readPrec :: ReadPrec (GNum a)
$creadPrec :: forall a. Read a => ReadPrec (GNum a)
readList :: ReadS [GNum a]
$creadList :: forall a. Read a => ReadS [GNum a]
readsPrec :: Int -> ReadS (GNum a)
$creadsPrec :: forall a. Read a => Int -> ReadS (GNum a)
Read, Typeable (GNum a)
DataType
Constr
Typeable (GNum a)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> GNum a -> c (GNum a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (GNum a))
-> (GNum a -> Constr)
-> (GNum a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (GNum a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (GNum a)))
-> ((forall b. Data b => b -> b) -> GNum a -> GNum a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> GNum a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> GNum a -> r)
-> (forall u. (forall d. Data d => d -> u) -> GNum a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> GNum a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> GNum a -> m (GNum a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> GNum a -> m (GNum a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> GNum a -> m (GNum a))
-> Data (GNum a)
GNum a -> DataType
GNum a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (GNum a))
(forall b. Data b => b -> b) -> GNum a -> GNum a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> GNum a -> c (GNum a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (GNum a)
forall a. Data a => Typeable (GNum a)
forall a. Data a => GNum a -> DataType
forall a. Data a => GNum a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> GNum a -> GNum a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> GNum a -> u
forall a u. Data a => (forall d. Data d => d -> u) -> GNum a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> GNum a -> r
forall a r r'.
Data a =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> GNum a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> GNum a -> m (GNum a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> GNum a -> m (GNum a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (GNum a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> GNum a -> c (GNum a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (GNum a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (GNum a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> GNum a -> u
forall u. (forall d. Data d => d -> u) -> GNum a -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> GNum a -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> GNum a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> GNum a -> m (GNum a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> GNum a -> m (GNum a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (GNum a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> GNum a -> c (GNum a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (GNum a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (GNum a))
$cGNum :: Constr
$tGNum :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> GNum a -> m (GNum a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> GNum a -> m (GNum a)
gmapMp :: (forall d. Data d => d -> m d) -> GNum a -> m (GNum a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> GNum a -> m (GNum a)
gmapM :: (forall d. Data d => d -> m d) -> GNum a -> m (GNum a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> GNum a -> m (GNum a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> GNum a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> GNum a -> u
gmapQ :: (forall d. Data d => d -> u) -> GNum a -> [u]
$cgmapQ :: forall a u. Data a => (forall d. Data d => d -> u) -> GNum a -> [u]
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> GNum a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> GNum a -> r
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> GNum a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> GNum a -> r
gmapT :: (forall b. Data b => b -> b) -> GNum a -> GNum a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> GNum a -> GNum a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (GNum a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (GNum a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (GNum a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (GNum a))
dataTypeOf :: GNum a -> DataType
$cdataTypeOf :: forall a. Data a => GNum a -> DataType
toConstr :: GNum a -> Constr
$ctoConstr :: forall a. Data a => GNum a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (GNum a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (GNum a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> GNum a -> c (GNum a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> GNum a -> c (GNum a)
$cp1Data :: forall a. Data a => Typeable (GNum a)
Data, (forall x. GNum a -> Rep (GNum a) x)
-> (forall x. Rep (GNum a) x -> GNum a) -> Generic (GNum a)
forall x. Rep (GNum a) x -> GNum a
forall x. GNum a -> Rep (GNum a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (GNum a) x -> GNum a
forall a x. GNum a -> Rep (GNum a) x
$cto :: forall a x. Rep (GNum a) x -> GNum a
$cfrom :: forall a x. GNum a -> Rep (GNum a) x
Generic, a -> GNum b -> GNum a
(a -> b) -> GNum a -> GNum b
(forall a b. (a -> b) -> GNum a -> GNum b)
-> (forall a b. a -> GNum b -> GNum a) -> Functor GNum
forall a b. a -> GNum b -> GNum a
forall a b. (a -> b) -> GNum a -> GNum b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> GNum b -> GNum a
$c<$ :: forall a b. a -> GNum b -> GNum a
fmap :: (a -> b) -> GNum a -> GNum b
$cfmap :: forall a b. (a -> b) -> GNum a -> GNum b
Functor, GNum a -> Bool
(a -> m) -> GNum a -> m
(a -> b -> b) -> b -> GNum a -> b
(forall m. Monoid m => GNum m -> m)
-> (forall m a. Monoid m => (a -> m) -> GNum a -> m)
-> (forall m a. Monoid m => (a -> m) -> GNum a -> m)
-> (forall a b. (a -> b -> b) -> b -> GNum a -> b)
-> (forall a b. (a -> b -> b) -> b -> GNum a -> b)
-> (forall b a. (b -> a -> b) -> b -> GNum a -> b)
-> (forall b a. (b -> a -> b) -> b -> GNum a -> b)
-> (forall a. (a -> a -> a) -> GNum a -> a)
-> (forall a. (a -> a -> a) -> GNum a -> a)
-> (forall a. GNum a -> [a])
-> (forall a. GNum a -> Bool)
-> (forall a. GNum a -> Int)
-> (forall a. Eq a => a -> GNum a -> Bool)
-> (forall a. Ord a => GNum a -> a)
-> (forall a. Ord a => GNum a -> a)
-> (forall a. Num a => GNum a -> a)
-> (forall a. Num a => GNum a -> a)
-> Foldable GNum
forall a. Eq a => a -> GNum a -> Bool
forall a. Num a => GNum a -> a
forall a. Ord a => GNum a -> a
forall m. Monoid m => GNum m -> m
forall a. GNum a -> Bool
forall a. GNum a -> Int
forall a. GNum a -> [a]
forall a. (a -> a -> a) -> GNum a -> a
forall m a. Monoid m => (a -> m) -> GNum a -> m
forall b a. (b -> a -> b) -> b -> GNum a -> b
forall a b. (a -> b -> b) -> b -> GNum a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: GNum a -> a
$cproduct :: forall a. Num a => GNum a -> a
sum :: GNum a -> a
$csum :: forall a. Num a => GNum a -> a
minimum :: GNum a -> a
$cminimum :: forall a. Ord a => GNum a -> a
maximum :: GNum a -> a
$cmaximum :: forall a. Ord a => GNum a -> a
elem :: a -> GNum a -> Bool
$celem :: forall a. Eq a => a -> GNum a -> Bool
length :: GNum a -> Int
$clength :: forall a. GNum a -> Int
null :: GNum a -> Bool
$cnull :: forall a. GNum a -> Bool
toList :: GNum a -> [a]
$ctoList :: forall a. GNum a -> [a]
foldl1 :: (a -> a -> a) -> GNum a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> GNum a -> a
foldr1 :: (a -> a -> a) -> GNum a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> GNum a -> a
foldl' :: (b -> a -> b) -> b -> GNum a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> GNum a -> b
foldl :: (b -> a -> b) -> b -> GNum a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> GNum a -> b
foldr' :: (a -> b -> b) -> b -> GNum a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> GNum a -> b
foldr :: (a -> b -> b) -> b -> GNum a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> GNum a -> b
foldMap' :: (a -> m) -> GNum a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> GNum a -> m
foldMap :: (a -> m) -> GNum a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> GNum a -> m
fold :: GNum m -> m
$cfold :: forall m. Monoid m => GNum m -> m
Foldable, Functor GNum
Foldable GNum
Functor GNum
-> Foldable GNum
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> GNum a -> f (GNum b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    GNum (f a) -> f (GNum a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> GNum a -> m (GNum b))
-> (forall (m :: * -> *) a. Monad m => GNum (m a) -> m (GNum a))
-> Traversable GNum
(a -> f b) -> GNum a -> f (GNum b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => GNum (m a) -> m (GNum a)
forall (f :: * -> *) a. Applicative f => GNum (f a) -> f (GNum a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> GNum a -> m (GNum b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> GNum a -> f (GNum b)
sequence :: GNum (m a) -> m (GNum a)
$csequence :: forall (m :: * -> *) a. Monad m => GNum (m a) -> m (GNum a)
mapM :: (a -> m b) -> GNum a -> m (GNum b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> GNum a -> m (GNum b)
sequenceA :: GNum (f a) -> f (GNum a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => GNum (f a) -> f (GNum a)
traverse :: (a -> f b) -> GNum a -> f (GNum b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> GNum a -> f (GNum b)
$cp2Traversable :: Foldable GNum
$cp1Traversable :: Functor GNum
Traversable)

instance (ADTRecord a, Constraints a Num)
      => Num (GNum a) where
    + :: GNum a -> GNum a -> GNum a
(+)         = (a -> a -> a) -> GNum a -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Num) => a -> a -> a
forall a. (ADTRecord a, Constraints a Num) => a -> a -> a
gPlus @a)
    {-# INLINE (+) #-}
    (-)         = (a -> a -> a) -> GNum a -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Num) => a -> a -> a
forall a. (ADTRecord a, Constraints a Num) => a -> a -> a
gMinus @a)
    {-# INLINE (-) #-}
    * :: GNum a -> GNum a -> GNum a
(*)         = (a -> a -> a) -> GNum a -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Num) => a -> a -> a
forall a. (ADTRecord a, Constraints a Num) => a -> a -> a
gTimes @a)
    {-# INLINE (*) #-}
    negate :: GNum a -> GNum a
negate      = (a -> a) -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Num) => a -> a
forall a. (ADTRecord a, Constraints a Num) => a -> a
gNegate @a)
    {-# INLINE negate #-}
    abs :: GNum a -> GNum a
abs         = (a -> a) -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Num) => a -> a
forall a. (ADTRecord a, Constraints a Num) => a -> a
gAbs @a)
    {-# INLINE abs #-}
    signum :: GNum a -> GNum a
signum      = (a -> a) -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Num) => a -> a
forall a. (ADTRecord a, Constraints a Num) => a -> a
gSignum @a)
    {-# INLINE signum #-}
    fromInteger :: Integer -> GNum a
fromInteger = (Integer -> a) -> Integer -> GNum a
coerce ((ADTRecord a, Constraints a Num) => Integer -> a
forall a. (ADTRecord a, Constraints a Num) => Integer -> a
gFromInteger @a)
    {-# INLINE fromInteger #-}

instance ( ADTRecord a
         , Constraints a Num
         , Constraints a Fractional
         )
      => Fractional (GNum a) where
    / :: GNum a -> GNum a -> GNum a
(/)          = (a -> a -> a) -> GNum a -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Fractional) => a -> a -> a
forall a. (ADTRecord a, Constraints a Fractional) => a -> a -> a
gDivide @a)
    {-# INLINE (/) #-}
    recip :: GNum a -> GNum a
recip        = (a -> a) -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Fractional) => a -> a
forall a. (ADTRecord a, Constraints a Fractional) => a -> a
gRecip @a)
    {-# INLINE recip #-}
    fromRational :: Rational -> GNum a
fromRational = (Rational -> a) -> Rational -> GNum a
coerce ((ADTRecord a, Constraints a Fractional) => Rational -> a
forall a. (ADTRecord a, Constraints a Fractional) => Rational -> a
gFromRational @a)
    {-# INLINE fromRational #-}

instance ( ADTRecord a
         , Constraints a Num
         , Constraints a Fractional
         , Constraints a Floating
         )
      => Floating (GNum a) where
    pi :: GNum a
pi      = a -> GNum a
coerce ((ADTRecord a, Constraints a Floating) => a
forall a. (ADTRecord a, Constraints a Floating) => a
gPi @a)
    {-# INLINE pi #-}
    exp :: GNum a -> GNum a
exp     = (a -> a) -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Floating) => a -> a
forall a. (ADTRecord a, Constraints a Floating) => a -> a
gExp @a)
    {-# INLINE exp #-}
    log :: GNum a -> GNum a
log     = (a -> a) -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Floating) => a -> a
forall a. (ADTRecord a, Constraints a Floating) => a -> a
gLog @a)
    {-# INLINE log #-}
    sqrt :: GNum a -> GNum a
sqrt    = (a -> a) -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Floating) => a -> a
forall a. (ADTRecord a, Constraints a Floating) => a -> a
gSqrt @a)
    {-# INLINE sqrt #-}
    ** :: GNum a -> GNum a -> GNum a
(**)    = (a -> a -> a) -> GNum a -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Floating) => a -> a -> a
forall a. (ADTRecord a, Constraints a Floating) => a -> a -> a
gPower @a)
    {-# INLINE (**) #-}
    logBase :: GNum a -> GNum a -> GNum a
logBase = (a -> a -> a) -> GNum a -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Floating) => a -> a -> a
forall a. (ADTRecord a, Constraints a Floating) => a -> a -> a
gLogBase @a)
    {-# INLINE logBase #-}
    sin :: GNum a -> GNum a
sin     = (a -> a) -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Floating) => a -> a
forall a. (ADTRecord a, Constraints a Floating) => a -> a
gSin @a)
    {-# INLINE sin #-}
    cos :: GNum a -> GNum a
cos     = (a -> a) -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Floating) => a -> a
forall a. (ADTRecord a, Constraints a Floating) => a -> a
gCos @a)
    {-# INLINE cos #-}
    tan :: GNum a -> GNum a
tan     = (a -> a) -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Floating) => a -> a
forall a. (ADTRecord a, Constraints a Floating) => a -> a
gTan @a)
    {-# INLINE tan #-}
    asin :: GNum a -> GNum a
asin    = (a -> a) -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Floating) => a -> a
forall a. (ADTRecord a, Constraints a Floating) => a -> a
gAsin @a)
    {-# INLINE asin #-}
    acos :: GNum a -> GNum a
acos    = (a -> a) -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Floating) => a -> a
forall a. (ADTRecord a, Constraints a Floating) => a -> a
gAcos @a)
    {-# INLINE acos #-}
    atan :: GNum a -> GNum a
atan    = (a -> a) -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Floating) => a -> a
forall a. (ADTRecord a, Constraints a Floating) => a -> a
gAtan @a)
    {-# INLINE atan #-}
    sinh :: GNum a -> GNum a
sinh    = (a -> a) -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Floating) => a -> a
forall a. (ADTRecord a, Constraints a Floating) => a -> a
gSinh @a)
    {-# INLINE sinh #-}
    cosh :: GNum a -> GNum a
cosh    = (a -> a) -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Floating) => a -> a
forall a. (ADTRecord a, Constraints a Floating) => a -> a
gCosh @a)
    {-# INLINE cosh #-}
    tanh :: GNum a -> GNum a
tanh    = (a -> a) -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Floating) => a -> a
forall a. (ADTRecord a, Constraints a Floating) => a -> a
gTanh @a)
    {-# INLINE tanh #-}
    asinh :: GNum a -> GNum a
asinh   = (a -> a) -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Floating) => a -> a
forall a. (ADTRecord a, Constraints a Floating) => a -> a
gAsinh @a)
    {-# INLINE asinh #-}
    acosh :: GNum a -> GNum a
acosh   = (a -> a) -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Floating) => a -> a
forall a. (ADTRecord a, Constraints a Floating) => a -> a
gAcosh @a)
    {-# INLINE acosh #-}
    atanh :: GNum a -> GNum a
atanh   = (a -> a) -> GNum a -> GNum a
coerce ((ADTRecord a, Constraints a Floating) => a -> a
forall a. (ADTRecord a, Constraints a Floating) => a -> a
gAtanh @a)
    {-# INLINE atanh #-}

-- $num
-- All of these implement the appropriate functions by carrying them over
-- every field of the data type

gPlus
    :: forall a. (ADTRecord a, Constraints a Num)
    => a -> a -> a
gPlus :: a -> a -> a
gPlus = (forall s. Num s => s -> s -> s) -> a -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s -> s) -> t -> t -> t
binaryOp @Num forall s. Num s => s -> s -> s
(+)
{-# INLINE gPlus #-}

gMinus
    :: forall a. (ADTRecord a, Constraints a Num)
    => a -> a -> a
gMinus :: a -> a -> a
gMinus = (forall s. Num s => s -> s -> s) -> a -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s -> s) -> t -> t -> t
binaryOp @Num (-)
{-# INLINE gMinus #-}

gTimes
    :: forall a. (ADTRecord a, Constraints a Num)
    => a -> a -> a
gTimes :: a -> a -> a
gTimes = (forall s. Num s => s -> s -> s) -> a -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s -> s) -> t -> t -> t
binaryOp @Num forall s. Num s => s -> s -> s
(*)
{-# INLINE gTimes #-}

gNegate
    :: forall a. (ADTRecord a, Constraints a Num)
    => a -> a
gNegate :: a -> a
gNegate = (forall s. Num s => s -> s) -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s) -> t -> t
unaryOp @Num forall s. Num s => s -> s
negate
{-# INLINE gNegate #-}

gAbs
    :: forall a. (ADTRecord a, Constraints a Num)
    => a -> a
gAbs :: a -> a
gAbs = (forall s. Num s => s -> s) -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s) -> t -> t
unaryOp @Num forall s. Num s => s -> s
abs
{-# INLINE gAbs #-}

gSignum
    :: forall a. (ADTRecord a, Constraints a Num)
    => a -> a
gSignum :: a -> a
gSignum = (forall s. Num s => s -> s) -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s) -> t -> t
unaryOp @Num forall s. Num s => s -> s
signum
{-# INLINE gSignum #-}

gFromInteger
    :: forall a. (ADTRecord a, Constraints a Num)
    => Integer -> a
gFromInteger :: Integer -> a
gFromInteger Integer
x = (forall s. Num s => s) -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s) -> t
nullaryOp @Num (Integer -> s
forall a. Num a => Integer -> a
fromInteger Integer
x)
{-# INLINE gFromInteger #-}

gDivide
    :: forall a. (ADTRecord a, Constraints a Fractional)
    => a -> a -> a
gDivide :: a -> a -> a
gDivide = (forall s. Fractional s => s -> s -> s) -> a -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s -> s) -> t -> t -> t
binaryOp @Fractional forall s. Fractional s => s -> s -> s
(/)
{-# INLINE gDivide #-}

gRecip
    :: forall a. (ADTRecord a, Constraints a Fractional)
    => a -> a
gRecip :: a -> a
gRecip = (forall s. Fractional s => s -> s) -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s) -> t -> t
unaryOp @Fractional forall s. Fractional s => s -> s
recip
{-# INLINE gRecip #-}

gFromRational
    :: forall a. (ADTRecord a, Constraints a Fractional)
    => Rational -> a
gFromRational :: Rational -> a
gFromRational Rational
x = (forall s. Fractional s => s) -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s) -> t
nullaryOp @Fractional (Rational -> s
forall a. Fractional a => Rational -> a
fromRational Rational
x)
{-# INLINE gFromRational #-}

gPi
    :: forall a. (ADTRecord a, Constraints a Floating)
    => a
gPi :: a
gPi = (forall s. Floating s => s) -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s) -> t
nullaryOp @Floating forall s. Floating s => s
pi
{-# INLINE gPi #-}

gExp
    :: forall a. (ADTRecord a, Constraints a Floating)
    => a -> a
gExp :: a -> a
gExp = (forall s. Floating s => s -> s) -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s) -> t -> t
unaryOp @Floating forall s. Floating s => s -> s
exp
{-# INLINE gExp #-}

gLog
    :: forall a. (ADTRecord a, Constraints a Floating)
    => a -> a
gLog :: a -> a
gLog = (forall s. Floating s => s -> s) -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s) -> t -> t
unaryOp @Floating forall s. Floating s => s -> s
log
{-# INLINE gLog #-}

gSqrt
    :: forall a. (ADTRecord a, Constraints a Floating)
    => a -> a
gSqrt :: a -> a
gSqrt = (forall s. Floating s => s -> s) -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s) -> t -> t
unaryOp @Floating forall s. Floating s => s -> s
sqrt
{-# INLINE gSqrt #-}

gPower
    :: forall a. (ADTRecord a, Constraints a Floating)
    => a -> a -> a
gPower :: a -> a -> a
gPower = (forall s. Floating s => s -> s -> s) -> a -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s -> s) -> t -> t -> t
binaryOp @Floating forall s. Floating s => s -> s -> s
(**)
{-# INLINE gPower #-}

gLogBase
    :: forall a. (ADTRecord a, Constraints a Floating)
    => a -> a -> a
gLogBase :: a -> a -> a
gLogBase = (forall s. Floating s => s -> s -> s) -> a -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s -> s) -> t -> t -> t
binaryOp @Floating forall s. Floating s => s -> s -> s
logBase
{-# INLINE gLogBase #-}

gSin
    :: forall a. (ADTRecord a, Constraints a Floating)
    => a -> a
gSin :: a -> a
gSin = (forall s. Floating s => s -> s) -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s) -> t -> t
unaryOp @Floating forall s. Floating s => s -> s
sin
{-# INLINE gSin #-}

gCos
    :: forall a. (ADTRecord a, Constraints a Floating)
    => a -> a
gCos :: a -> a
gCos = (forall s. Floating s => s -> s) -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s) -> t -> t
unaryOp @Floating forall s. Floating s => s -> s
cos
{-# INLINE gCos #-}

gTan
    :: forall a. (ADTRecord a, Constraints a Floating)
    => a -> a
gTan :: a -> a
gTan = (forall s. Floating s => s -> s) -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s) -> t -> t
unaryOp @Floating forall s. Floating s => s -> s
tan
{-# INLINE gTan #-}

gAsin
    :: forall a. (ADTRecord a, Constraints a Floating)
    => a -> a
gAsin :: a -> a
gAsin = (forall s. Floating s => s -> s) -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s) -> t -> t
unaryOp @Floating forall s. Floating s => s -> s
asin
{-# INLINE gAsin #-}

gAcos
    :: forall a. (ADTRecord a, Constraints a Floating)
    => a -> a
gAcos :: a -> a
gAcos = (forall s. Floating s => s -> s) -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s) -> t -> t
unaryOp @Floating forall s. Floating s => s -> s
acos
{-# INLINE gAcos #-}

gAtan
    :: forall a. (ADTRecord a, Constraints a Floating)
    => a -> a
gAtan :: a -> a
gAtan = (forall s. Floating s => s -> s) -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s) -> t -> t
unaryOp @Floating forall s. Floating s => s -> s
atan
{-# INLINE gAtan #-}

gSinh
    :: forall a. (ADTRecord a, Constraints a Floating)
    => a -> a
gSinh :: a -> a
gSinh = (forall s. Floating s => s -> s) -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s) -> t -> t
unaryOp @Floating forall s. Floating s => s -> s
sinh
{-# INLINE gSinh #-}

gCosh
    :: forall a. (ADTRecord a, Constraints a Floating)
    => a -> a
gCosh :: a -> a
gCosh = (forall s. Floating s => s -> s) -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s) -> t -> t
unaryOp @Floating forall s. Floating s => s -> s
cosh
{-# INLINE gCosh #-}

gTanh
    :: forall a. (ADTRecord a, Constraints a Floating)
    => a -> a
gTanh :: a -> a
gTanh = (forall s. Floating s => s -> s) -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s) -> t -> t
unaryOp @Floating forall s. Floating s => s -> s
atanh
{-# INLINE gTanh #-}

gAsinh
    :: forall a. (ADTRecord a, Constraints a Floating)
    => a -> a
gAsinh :: a -> a
gAsinh = (forall s. Floating s => s -> s) -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s) -> t -> t
unaryOp @Floating forall s. Floating s => s -> s
asinh
{-# INLINE gAsinh #-}

gAcosh
    :: forall a. (ADTRecord a, Constraints a Floating)
    => a -> a
gAcosh :: a -> a
gAcosh = (forall s. Floating s => s -> s) -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s) -> t -> t
unaryOp @Floating forall s. Floating s => s -> s
acosh
{-# INLINE gAcosh #-}

gAtanh
    :: forall a. (ADTRecord a, Constraints a Floating)
    => a -> a
gAtanh :: a -> a
gAtanh = (forall s. Floating s => s -> s) -> a -> a
forall (c :: * -> Constraint) t.
(ADTRecord t, Constraints t c) =>
(forall s. c s => s -> s) -> t -> t
unaryOp @Floating forall s. Floating s => s -> s
atanh
{-# INLINE gAtanh #-}