Safe Haskell | Safe |
---|---|
Language | Haskell98 |
- class C a => C a where
- (*) :: C a => a -> a -> a
- one :: C a => a
- fromInteger :: C a => Integer -> a
- (^) :: C a => a -> Integer -> a
- sqr :: C a => a -> a
- product :: C a => [a] -> a
- product1 :: C a => [a] -> a
- scalarProduct :: C a => [a] -> [a] -> a
- propAssociative :: (Eq a, C a) => a -> a -> a -> Bool
- propLeftDistributive :: (Eq a, C a) => a -> a -> a -> Bool
- propRightDistributive :: (Eq a, C a) => a -> a -> a -> Bool
- propLeftIdentity :: (Eq a, C a) => a -> Bool
- propRightIdentity :: (Eq a, C a) => a -> Bool
- propPowerCascade :: (Eq a, C a) => a -> Integer -> Integer -> Property
- propPowerProduct :: (Eq a, C a) => a -> Integer -> Integer -> Property
- propPowerDistributive :: (Eq a, C a) => Integer -> a -> a -> Property
- propCommutative :: (Eq a, C a) => a -> a -> Bool
Class
class C a => C a where Source #
Ring encapsulates the mathematical structure of a (not necessarily commutative) ring, with the laws
a * (b * c) === (a * b) * c one * a === a a * one === a a * (b + c) === a * b + a * c
Typical examples include integers, polynomials, matrices, and quaternions.
Minimal definition: *
, (one
or fromInteger
)
(*), (one | fromInteger)
(*) :: a -> a -> a infixl 7 Source #
fromInteger :: Integer -> a Source #
(^) :: a -> Integer -> a infixr 8 Source #
The exponent has fixed type Integer
in order
to avoid an arbitrarily limitted range of exponents,
but to reduce the need for the compiler to guess the type (default type).
In practice the exponent is most oftenly fixed, and is most oftenly 2
.
Fixed exponents can be optimized away and
thus the expensive computation of Integer
s doesn't matter.
The previous solution used a C
constrained type
and the exponent was converted to Integer before computation.
So the current solution is not less efficient.
A variant of ^
with more flexibility is provided by ringPower
.
C Double Source # | |
C Float Source # | |
C Int Source # | |
C Int8 Source # | |
C Int16 Source # | |
C Int32 Source # | |
C Int64 Source # | |
C Integer Source # | |
C Word Source # | |
C Word8 Source # | |
C Word16 Source # | |
C Word32 Source # | |
C Word64 Source # | |
C T Source # | |
C T Source # | |
C T Source # | |
C T Source # | |
Integral a => C (Ratio a) Source # | |
RealFloat a => C (Complex a) Source # | |
C a => C (T a) Source # | |
Num a => C (T a) Source # | |
(Eq a, C a) => C (T a) Source # | |
C a => C (T a) Source # | |
(Eq a, C a) => C (T a) Source # | |
C a => C (T a) Source # | |
(C a, C a) => C (T a) Source # | |
C a => C (T a) Source # | |
C a => C (T a) Source # | |
C a => C (T a) Source # | |
C a => C (T a) Source # | |
(C a, C a) => C (T a) Source # | |
(C a, C a) => C (T a) Source # | |
C a => C (T a) Source # | |
C a => C (T a) Source # | |
C a => C (T a) Source # | |
C a => C (T a) Source # | |
C a => C (T a) Source # | |
(Ord a, C a, C b) => C (T a b) Source # | |
C v => C (T a v) Source # | |
(IsScalar u, C a) => C (T u a) Source # | |
(Ord i, C a) => C (T i a) Source # | |
C v => C (T a v) Source # | |
fromInteger :: C a => Integer -> a Source #
(^) :: C a => a -> Integer -> a infixr 8 Source #
The exponent has fixed type Integer
in order
to avoid an arbitrarily limitted range of exponents,
but to reduce the need for the compiler to guess the type (default type).
In practice the exponent is most oftenly fixed, and is most oftenly 2
.
Fixed exponents can be optimized away and
thus the expensive computation of Integer
s doesn't matter.
The previous solution used a C
constrained type
and the exponent was converted to Integer before computation.
So the current solution is not less efficient.
A variant of ^
with more flexibility is provided by ringPower
.
Complex functions
scalarProduct :: C a => [a] -> [a] -> a Source #