on package:numhask

on b u x y runs the binary function b on the results of applying unary function u to two arguments x and y. From the opposite perspective, it transforms two inputs and combines the outputs.
((+) `on` f) x y = f x + f y
Typical usage: sortBy (compare `on` fst). Algebraic properties:
  • (*) `on` id = (*) -- (if (*) ∉ {⊥, const
    ⊥})
  • ((*) `on` f) `on` g = (*) `on` (f . g)
  • flip on f . flip on g = flip on (g .
    f)
Additive Action
m |+ zero == m
Convert between a "co-ordinated" or "higher-kinded" number and a direction.
ray . angle == basis
magnitude (ray x) == one
Divisive Action
m |/ one = m
A small number, especially useful for approximate equality.
fromRational is special in two ways:
  • numeric decimal literals (like "53.66") are interpreted as exactly "fromRational (53.66 :: GHC.Real.Ratio Integer)". The prelude version, GHC.Real.fromRational is used as default (or whatever is in scope if RebindableSyntax is set).
  • The default rules in haskell2010 specify that contraints on fromRational need to be in a form C v, where v is a Num or a subclass of Num.
So a type synonym of `type FromRational a = FromRatio a Integer` doesn't work well with type defaulting; hence the need for a separate class.
Multiplicative Action
m |* one = m
m |* zero = zero
A numhask exception.
Arbitrary-precision rational numbers, represented as a ratio of two Integer values. A rational number may be constructed using the % operator.
Subtractive Action
m |- zero = m
Algebra for Actions Convention: the |'s in the operators point towards the higher-kinded number, representing an operator or action into a structure.
Rational classes
Exceptions arising within numhask.
Fractional numbers, supporting real division. The Haskell Report defines no laws for Fractional. However, (+) and (*) are customarily expected to define a division ring and have the following properties:
  • recip gives the multiplicative inverse x * recip x = recip x * x = fromInteger 1
Note that it isn't customarily expected that a type instance of Fractional implement a field. However, all instances in base do.
The Monad class defines the basic operations over a monad, a concept from a branch of mathematics known as category theory. From the perspective of a Haskell programmer, however, it is best to think of a monad as an abstract datatype of actions. Haskell's do expressions provide a convenient syntax for writing monadic expressions. Instances of Monad should satisfy the following: Furthermore, the Monad and Applicative operations should relate as follows: The above laws imply: and that pure and (<*>) satisfy the applicative functor laws. The instances of Monad for lists, Maybe and IO defined in the Prelude satisfy these laws.
When a value is bound in do-notation, the pattern on the left hand side of <- might not match. In this case, this class provides a function to recover. A Monad without a MonadFail instance may only be used in conjunction with pattern that always match, such as newtypes, tuples, data types with only a single data constructor, and irrefutable patterns (~pat). Instances of MonadFail should satisfy the following law: fail s should be a left zero for >>=,
fail s >>= f  =  fail s
If your Monad is also MonadPlus, a popular definition is
fail _ = mzero
The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following: The method names refer to the monoid of lists under concatenation, but there are many other instances. Some types can be viewed as a monoid in more than one way, e.g. both addition and multiplication on numbers. In such cases we often define newtypes and make those instances of Monoid, e.g. Sum and Product. NOTE: Semigroup is a superclass of Monoid since base-4.11.0.0.
The concatenation of all the elements of a container of lists.

Examples

Basic usage:
>>> concat (Just [1, 2, 3])
[1,2,3]
>>> concat (Left 42)
[]
>>> concat [[1, 2, 3], [4, 5], [6], []]
[1,2,3,4,5,6]
Map a function over all the elements of a container and concatenate the resulting lists.

Examples

Basic usage:
>>> concatMap (take 3) [[1..], [10..], [100..], [1000..]]
[1,2,3,10,11,12,100,101,102,1000,1001,1002]
>>> concatMap (take 3) (Just [1..])
[1,2,3]
const x is a unary function which evaluates to x for all inputs.
>>> const 42 "hello"
42
>>> map (const 42) [0..3]
[42,42,42,42]