FR
PréludeChargé par défaut — aucun import nécessaire.

FromNat — numeric literal overloading

Synopsis

Rational — exact rational numbers

FromDecimal — decimal literal overloading

Additive — addition and zero

Multiplicative — multiplication and one

AdditiveGroup — subtraction and negation

interface Abs a where
abs : a -> a

Absolute value: drops the sign. A CLASS, so each signed type provides its own (a user type can too). abs (-5) = 5, abs 5 = 5. (Nat is always non-negative, so it is not an instance.)

Instances : Double, Int, Int16, Int32, Int64, Int8

Semiring — addition and multiplication with distribution

EuclideanDiv — integer division and modulo

interface Semiring a => EuclideanDiv a where
div : a -> a -> a
mod : a -> a -> a

Integer division with Euclidean semantics. On Semiring (not Ring), so Nat has div/mod too — the same div/mod as Int. The remainder is always non-negative. div (-7) 3 = -3, mod (-7) 3 = 2 (not -1 as in C). Law: div x y * y + mod x y = x

Ring — a semiring with subtraction

CommutativeRing — commutative multiplication

EuclideanRing — a Euclidean domain

interface CommutativeRing a => EuclideanDiv a => EuclideanRing a where {}

A commutative ring with Euclidean division. Marker interface (= CommutativeRing + EuclideanDiv). Nat is not one (no negate), though it still has EuclideanDiv. Note: Double is intentionally NOT EuclideanDiv/EuclideanRing/Field yet — whether Double's div/mod should be truncated or the trivial field structure (div = /, mod = zero) is still open.

DivisionRing — reciprocal and real division

interface Ring a => DivisionRing a where
recip : a -> a
(/) : a -> a -> a

Real division and reciprocal. Extends Ring. For continuous types (Double). Not for integer division.

Instances : Double, Rational

Floating-point functions on Double

pi : Double

π, to double precision.

interface Floating a where
sqrt : a -> a
exp : a -> a
ln : a -> a
sin : a -> a
cos : a -> a
tan : a -> a

Floating collects the transcendental FUNCTIONS. Double is the only instance so far; the CLASS makes them generic so other floating types (a future arbitrary-precision float, …) can join. ln is undefined for non-positive inputs; sin/cos/tan take radians.

Instances : Double