Copyright | (c) Justin Le 2021 |
---|---|
License | BSD-3 |
Maintainer | justin@jle.im |
Stability | unstable |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
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.
Synopsis
- newtype GNum a = GNum {
- getGNum :: a
- gPlus :: forall a. (ADTRecord a, Constraints a Num) => a -> a -> a
- gMinus :: forall a. (ADTRecord a, Constraints a Num) => a -> a -> a
- gTimes :: forall a. (ADTRecord a, Constraints a Num) => a -> a -> a
- gNegate :: forall a. (ADTRecord a, Constraints a Num) => a -> a
- gAbs :: forall a. (ADTRecord a, Constraints a Num) => a -> a
- gSignum :: forall a. (ADTRecord a, Constraints a Num) => a -> a
- gFromInteger :: forall a. (ADTRecord a, Constraints a Num) => Integer -> a
- gDivide :: forall a. (ADTRecord a, Constraints a Fractional) => a -> a -> a
- gRecip :: forall a. (ADTRecord a, Constraints a Fractional) => a -> a
- gFromRational :: forall a. (ADTRecord a, Constraints a Fractional) => Rational -> a
- gPi :: forall a. (ADTRecord a, Constraints a Floating) => a
- gExp :: forall a. (ADTRecord a, Constraints a Floating) => a -> a
- gLog :: forall a. (ADTRecord a, Constraints a Floating) => a -> a
- gSqrt :: forall a. (ADTRecord a, Constraints a Floating) => a -> a
- gPower :: forall a. (ADTRecord a, Constraints a Floating) => a -> a -> a
- gLogBase :: forall a. (ADTRecord a, Constraints a Floating) => a -> a -> a
- gSin :: forall a. (ADTRecord a, Constraints a Floating) => a -> a
- gCos :: forall a. (ADTRecord a, Constraints a Floating) => a -> a
- gTan :: forall a. (ADTRecord a, Constraints a Floating) => a -> a
- gAsin :: forall a. (ADTRecord a, Constraints a Floating) => a -> a
- gAcos :: forall a. (ADTRecord a, Constraints a Floating) => a -> a
- gAtan :: forall a. (ADTRecord a, Constraints a Floating) => a -> a
- gSinh :: forall a. (ADTRecord a, Constraints a Floating) => a -> a
- gCosh :: forall a. (ADTRecord a, Constraints a Floating) => a -> a
- gTanh :: forall a. (ADTRecord a, Constraints a Floating) => a -> a
- gAsinh :: forall a. (ADTRecord a, Constraints a Floating) => a -> a
- gAcosh :: forall a. (ADTRecord a, Constraints a Floating) => a -> a
- gAtanh :: forall a. (ADTRecord a, Constraints a Floating) => a -> a
Newtype wrapper
If a
is a data type with a single constructor whose fields are all
instances of Num
, then
has a GNum
aNum
instance.
If a
is a data type with a single constructor whose fields are all
instances of Fractional
, then
has a GNum
aFractional
instance.
If a
is a data type with a single constructor whose fields are all
instances of Floating
, then
has a GNum
aFloating
instance.
Will one day be able to be used with DerivingVia syntax, to derive instances automatically.
Instances
Functor GNum Source # | |
Foldable GNum Source # | |
Defined in Numeric.OneLiner fold :: Monoid m => GNum m -> m # foldMap :: Monoid m => (a -> m) -> GNum a -> m # foldMap' :: Monoid m => (a -> m) -> GNum a -> m # foldr :: (a -> b -> b) -> b -> GNum a -> b # foldr' :: (a -> b -> b) -> b -> GNum a -> b # foldl :: (b -> a -> b) -> b -> GNum a -> b # foldl' :: (b -> a -> b) -> b -> GNum a -> b # foldr1 :: (a -> a -> a) -> GNum a -> a # foldl1 :: (a -> a -> a) -> GNum a -> a # elem :: Eq a => a -> GNum a -> Bool # maximum :: Ord a => GNum a -> a # | |
Traversable GNum Source # | |
Eq a => Eq (GNum a) Source # | |
(ADTRecord a, Constraints a Num, Constraints a Fractional, Constraints a Floating) => Floating (GNum a) Source # | |
(ADTRecord a, Constraints a Num, Constraints a Fractional) => Fractional (GNum a) Source # | |
Data a => Data (GNum a) Source # | |
Defined in Numeric.OneLiner gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> GNum a -> c (GNum a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (GNum a) # toConstr :: GNum a -> Constr # dataTypeOf :: GNum a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (GNum a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (GNum a)) # gmapT :: (forall b. Data b => b -> b) -> GNum a -> GNum a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> GNum a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> GNum a -> r # gmapQ :: (forall d. Data d => d -> u) -> GNum a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> GNum a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> GNum a -> m (GNum a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> GNum a -> m (GNum a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> GNum a -> m (GNum a) # | |
(ADTRecord a, Constraints a Num) => Num (GNum a) Source # | |
Ord a => Ord (GNum a) Source # | |
Read a => Read (GNum a) Source # | |
Show a => Show (GNum a) Source # | |
Generic (GNum a) Source # | |
type Rep (GNum a) Source # | |
Defined in Numeric.OneLiner |
Generics-derived methods
All of these implement the appropriate functions by carrying them over every field of the data type
gFromInteger :: forall a. (ADTRecord a, Constraints a Num) => Integer -> a Source #
Fractional
gDivide :: forall a. (ADTRecord a, Constraints a Fractional) => a -> a -> a Source #
gRecip :: forall a. (ADTRecord a, Constraints a Fractional) => a -> a Source #
gFromRational :: forall a. (ADTRecord a, Constraints a Fractional) => Rational -> a Source #