units-2.4.1.2: A domain-specific type system for dimensional analysis

Copyright (C) 2014 Richard Eisenberg (C) 2015 Tobias Markus BSD-style (see LICENSE) Richard Eisenberg (rae@cs.brynmawr.edu) experimental non-portable None Haskell2010

Data.Metrology.Linear

Description

Exports combinators for building quantities out of vectors, from the linear library.

Synopsis

# Term-level combinators

The term-level arithmetic operators are defined by applying vertical bar(s) to the sides the dimensioned quantities acts on.

zeroV :: (Additive f, Num a) => Qu d l (f a) Source #

The number 0, polymorphic in its dimension. Use of this will often require a type annotation.

(|^+^|) :: (d1 @~ d2, Additive f, Num a) => Qu d1 l (f a) -> Qu d2 l (f a) -> Qu d1 l (f a) infixl 6 Source #

(|^-^|) :: (d1 @~ d2, Additive f, Num a) => Qu d1 l (f a) -> Qu d2 l (f a) -> Qu d1 l (f a) infixl 6 Source #

Subtract two compatible quantities

qNegateV :: (Additive f, Num a) => Qu d l (f a) -> Qu d l (f a) Source #

Negate a vector quantity

qSumV :: (Foldable t, Additive f, Num a) => t (Qu d l (f a)) -> Qu d l (f a) Source #

Take the sum of a list of quantities

## Multiplicative operations

(|*^|) :: (Functor f, Num a) => Qu d1 l a -> Qu d2 l (f a) -> Qu (Normalize (d1 @+ d2)) l (f a) infixl 7 Source #

Multiply a scalar quantity by a vector quantity

(|^*|) :: (Functor f, Num a) => Qu d1 l (f a) -> Qu d2 l a -> Qu (Normalize (d1 @+ d2)) l (f a) infixl 7 Source #

Multiply a vector quantity by a scalar quantity

(|^/|) :: (Functor f, Fractional a) => Qu d1 l (f a) -> Qu d2 l a -> Qu (Normalize (d1 @- d2)) l (f a) infixl 7 Source #

Divide a vector quantity by a scalar quantity

(*^|) :: (Functor f, Num a) => a -> Qu b l (f a) -> Qu b l (f a) infixl 7 Source #

Multiply a quantity by a plain old number from the left

(|^*) :: (Functor f, Num a) => Qu b l (f a) -> a -> Qu b l (f a) infixl 7 Source #

Multiply a quantity by a plain old number from the right

(|^/) :: (Functor f, Fractional a) => Qu d l (f a) -> a -> Qu d l (f a) infixl 7 Source #

Divide a quantity by a plain old number

(|.|) :: (Metric f, Num a) => Qu d1 l (f a) -> Qu d2 l (f a) -> Qu (Normalize (d1 @+ d2)) l a infixl 7 Source #

Take a inner (dot) product between two quantities.

## Vector-space operations

qBasis :: (ValidDLU dim lcsu unit, Additive f, Traversable f, Fractional a) => unit -> [Qu dim lcsu (f a)] Source #

Return a default basis, where each basis element measures 1 of the unit provided.

qBasisFor :: (ValidDLU dim lcsu unit, Additive f, Traversable f, Fractional a) => unit -> Qu dim lcsu (f b) -> [Qu dim lcsu (f a)] Source #

Return a default basis for the vector space provided. Each basis element measures 1 of the unit provided.

qScaled :: (Traversable f, Num a) => Qu dim lcsu (f a) -> Qu dim lcsu (f (f a)) Source #

Produce a diagonal (scale) matrix from a vector

qOuter :: (Functor f, Functor g, Num a) => Qu d1 l (f a) -> Qu d2 l (g a) -> Qu (Normalize (d1 @+ d2)) l (f (g a)) Source #

Outer (tensor) product of two quantity vectors

qUnit :: (ValidDLU dim lcsu unit, Additive t, Fractional a) => ASetter' (t a) a -> unit -> Qu dim lcsu (t a) Source #

Create a unit vector from a setter and a choice of unit.

qQuadrance :: (Metric f, Num a) => Qu d l (f a) -> Qu (d @* Two) l a Source #

Square the length of a vector.

qNorm :: (Metric f, Floating a) => Qu d l (f a) -> Qu d l a Source #

Length of a vector.

qSignorm :: (Metric f, Floating a) => Qu d l (f a) -> Qu '[] l (f a) Source #

Vector in same direction as given one but with length of one. If given the zero vector, then return it. The returned vector is dimensionless.

qProject :: (Metric f, Fractional a) => Qu d2 l (f a) -> Qu d1 l (f a) -> Qu d1 l (f a) Source #

qProject u v computes the projection of v onto u.

qCross :: Num a => Qu d1 l (V3 a) -> Qu d2 l (V3 a) -> Qu (Normalize (d1 @+ d2)) l (V3 a) Source #

Cross product of 3D vectors.

## Affine operations

(|.-.|) :: (d1 @~ d2, Affine f, Num a) => Qu d1 l (f a) -> Qu d2 l (f a) -> Qu d1 l (Diff f a) Source #

Subtract point quantities.

(|.+^|) :: (d1 @~ d2, Affine f, Num a) => Qu d1 l (f a) -> Qu d2 l (Diff f a) -> Qu d1 l (f a) Source #

Add a point to a vector.

(|.-^|) :: (d1 @~ d2, Affine f, Num a) => Qu d1 l (f a) -> Qu d2 l (Diff f a) -> Qu d1 l (f a) Source #

Subract a vector from a point.

qQd :: (d1 @~ d2, Metric f, Metric (Diff f), Num a) => Qu d1 l (f a) -> Qu d2 l (f a) -> Qu (d1 @* Two) l a Source #

Square of the distance between two vectors.

qDistance :: (d1 @~ d2, Metric f, Metric (Diff f), Floating a) => Qu d1 l (f a) -> Qu d2 l (f a) -> Qu d1 l a Source #

Distance between two vectors.

qQdA :: (d1 @~ d2, Affine f, Foldable (Diff f), Num a) => Qu d1 l (f a) -> Qu d2 l (f a) -> Qu (d1 @* Two) l a Source #

Square of the distance between two points.

qDistanceA :: (d1 @~ d2, Affine f, Foldable (Diff f), Floating a) => Qu d1 l (f a) -> Qu d2 l (f a) -> Qu d1 l a Source #

Distance between two points.

# Nondimensional units, conversion between quantities and numeric values

numInV :: forall unit dim lcsu f a. (ValidDLU dim lcsu unit, Functor f, Fractional a) => Qu dim lcsu (f a) -> unit -> f a Source #

Extracts a numerical value from a dimensioned quantity, expressed in the given unit. For example:

inMeters :: Length -> Double
inMeters x = numIn x Meter

or

inMeters x = x # Meter

(^#) :: (ValidDLU dim lcsu unit, Functor f, Fractional a) => Qu dim lcsu (f a) -> unit -> f a infix 5 Source #

Infix synonym for numIn

quOfV :: forall unit dim lcsu f a. (ValidDLU dim lcsu unit, Functor f, Fractional a) => f a -> unit -> Qu dim lcsu (f a) Source #

Creates a dimensioned quantity in the given unit. For example:

height :: Length
height = quOf 2.0 Meter

or

height = 2.0 % Meter

(^%) :: (ValidDLU dim lcsu unit, Functor f, Fractional a) => f a -> unit -> Qu dim lcsu (f a) infixr 9 Source #

Infix synonym for quOf

showInV :: (ValidDLU dim lcsu unit, Functor f, Fractional a, Show unit, Show a, Show (f a)) => Qu dim lcsu (f a) -> unit -> String infix 1 Source #

Show a dimensioned quantity in a given unit. (The default Show instance always uses units as specified in the LCSU.)

convertV :: forall d l1 l2 f a. (ConvertibleLCSUs d l1 l2, Functor f, Fractional a) => Qu d l1 (f a) -> Qu d l2 (f a) Source #

Dimension-keeping cast between different CSUs.

constantV :: (d @~ e, ConvertibleLCSUs e DefaultLCSU l, Functor f, Fractional a) => Qu d DefaultLCSU (f a) -> Qu e l (f a) Source #

Compute the argument in the DefaultLCSU, and present the result as lcsu-polymorphic dimension-polymorphic value. Named constant because one of its dominant usecase is to inject constant quantities into dimension-polymorphic expressions.