diagrams-lib- Embedded domain-specific language for declarative graphics

Safe HaskellSafe-Inferred



Nice syntax for constructing and pattern-matching on literal points and vectors.



data a :& b Source

A pair of values, with a convenient infix (left-associative) data constructor.


a :& b 


(Eq a, Eq b) => Eq (:& a b) 
(Eq (:& a b), Ord a, Ord b) => Ord (:& a b) 
(Show a, Show b) => Show (:& a b) 

class Coordinates c whereSource

Types which are instances of the Coordinates class can be constructed using & (for example, a three-dimensional vector could be constructed by 1 & 6 & 3), and deconstructed using coords. A common pattern is to use coords in conjunction with the ViewPatterns extension, like so:

 foo :: Vector3 -> ...
 foo (coords -> x :& y :& z) = ...

Associated Types

type FinalCoord c :: *Source

The type of the final coordinate.

type PrevDim c :: *Source

The type of everything other than the final coordinate.

type Decomposition c :: *Source

Decomposition of c into applications of :&.


(&) :: PrevDim c -> FinalCoord c -> cSource

Construct a value of type c by providing something of one less dimension (which is perhaps itself recursively constructed using (&)) and a final coordinate. For example,

 2 & 3 :: P2
 3 & 5 & 6 :: R3

Note that & is left-associative.

coords :: c -> Decomposition cSource

Decompose a value of type c into its constituent coordinates, stored in a nested (:&) structure.