| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
NumHask.Algebra.Abstract
Contents
Description
The abstract algebraic class structure of a number.
Synopsis
- module NumHask.Algebra.Abstract.Group
- module NumHask.Algebra.Abstract.Additive
- module NumHask.Algebra.Abstract.Multiplicative
- module NumHask.Algebra.Abstract.Ring
- module NumHask.Algebra.Abstract.Field
- module NumHask.Algebra.Abstract.Module
- module NumHask.Algebra.Abstract.Action
- module NumHask.Algebra.Abstract.Lattice
- module NumHask.Algebra.Abstract.Homomorphism
Mapping from Num
Num is a very old part of haskell, and a lot of different numeric concepts are tossed in there. The closest analogue in numhask is the Ring class, which magmaines the classical Additive, Subtractive and Multiplicative, together with the Distributive laws.
No attempt is made, however, to reconstruct the particular magmaination of laws and classes that represent the old Num. A rough mapping of Num to numhask classes follows:
-- | Basic numeric class.
class Num a where
{-# MINIMAL (+), (*), abs, signum, fromInteger, (negate | (-)) #-}
(+), (-), (*) :: a -> a -> a
-- | Unary negation.
negate :: a -> aAdditive is a function of the Additive class,
Subtractive is a function of the Subtractive class, and
Multiplicative is a function of the Multiplicative class.
Subtractive is specifically in the Subtractive class. There are many useful constructions between negate and (-), involving cancellative properties.
-- | Absolute value. abs :: a -> a -- | Sign of a number. -- The functions 'abs' and 'signum' should satisfy the law: -- -- > abs x * signum x == x -- -- For real numbers, the 'signum' is either @-1@ (negative), @0@ (zero) -- or @1@ (positive). signum :: a -> a
abs is a function in the Signed class. The concept of an absolute value of a number can include situations where the domain and codomain are different, and size as a function in the Normed class is supplied for these cases.
sign replaces signum, because signum is a heinous name.
-- | Conversion from an 'Integer'.
-- An integer literal represents the application of the function
-- 'fromInteger' to the appropriate value of type 'Integer',
-- so such literals have type @('Num' a) => a@.
fromInteger :: Integer -> afromInteger is given its own class FromInteger