fixed-vector-1.2.3.0: Generic vectors with statically known size.
Safe HaskellNone
LanguageHaskell2010

Data.Vector.Fixed

Description

Generic API for vectors with fixed length.

For encoding of vector size library uses Peano naturals defined in the library. At come point in the future it would make sense to switch to new GHC type level numerals.

Common pitfalls

Library provide instances for tuples. But there's a catch. Tuples are monomorphic in element type. Let consider 2-tuple (Int,Int). Vector type v is (,) Int and only allowed element type is Int. Because of that we cannot change element type and following code will fail:

>>> map (== 1) ((1,2) :: (Int,Int))

<interactive>:3:1:
    Couldn't match type `Int' with `Bool'
    In the expression: F.map (== 1) ((1, 2) :: (Int, Int))
    In an equation for `it': it = map (== 1) ((1, 2) :: (Int, Int))

To make it work we need to change vector type as well. Functions from module Data.Vector.Fixed.Generic provide this functionality.

>>> map (== 1) ((1,2) :: (Int,Int)) :: (Bool,Bool)
(True,False)
Synopsis

Vector type class

Vector size

type family Dim (v :: Type -> Type) :: Nat Source #

Size of vector expressed as type-level natural.

Instances

Instances details
type Dim Complex Source # 
Instance details

Defined in Data.Vector.Fixed.Cont

type Dim Complex = 2
type Dim Only Source # 
Instance details

Defined in Data.Vector.Fixed

type Dim Only = 1
type Dim Identity Source # 
Instance details

Defined in Data.Vector.Fixed.Cont

type Dim Identity = 1
type Dim (Empty :: Type -> Type) Source # 
Instance details

Defined in Data.Vector.Fixed

type Dim (Empty :: Type -> Type) = 0
type Dim (VecList n) Source # 
Instance details

Defined in Data.Vector.Fixed

type Dim (VecList n) = n
type Dim (Vec n) Source # 
Instance details

Defined in Data.Vector.Fixed.Boxed

type Dim (Vec n) = n
type Dim (ContVec n) Source # 
Instance details

Defined in Data.Vector.Fixed.Cont

type Dim (ContVec n) = n
type Dim (Vec n) Source # 
Instance details

Defined in Data.Vector.Fixed.Primitive

type Dim (Vec n) = n
type Dim (Vec n) Source # 
Instance details

Defined in Data.Vector.Fixed.Storable

type Dim (Vec n) = n
type Dim (Vec n) Source # 
Instance details

Defined in Data.Vector.Fixed.Unboxed

type Dim (Vec n) = n
type Dim (Proxy :: Type -> Type) Source # 
Instance details

Defined in Data.Vector.Fixed.Cont

type Dim (Proxy :: Type -> Type) = 0
type Dim ((,) a) Source # 
Instance details

Defined in Data.Vector.Fixed.Cont

type Dim ((,) a) = 2
type Dim ((,,) a b) Source # 
Instance details

Defined in Data.Vector.Fixed.Cont

type Dim ((,,) a b) = 3
type Dim ((,,,) a b c) Source # 
Instance details

Defined in Data.Vector.Fixed.Cont

type Dim ((,,,) a b c) = 4
type Dim ((,,,,) a b c d) Source # 
Instance details

Defined in Data.Vector.Fixed.Cont

type Dim ((,,,,) a b c d) = 5
type Dim ((,,,,,) a b c d e) Source # 
Instance details

Defined in Data.Vector.Fixed.Cont

type Dim ((,,,,,) a b c d e) = 6
type Dim ((,,,,,,) a b c d e f) Source # 
Instance details

Defined in Data.Vector.Fixed.Cont

type Dim ((,,,,,,) a b c d e f) = 7

Type class

class Arity (Dim v) => Vector (v :: Type -> Type) a where Source #

Type class for vectors with fixed length. Instance should provide two functions: one to create vector and another for vector deconstruction. They must obey following law:

inspect v construct = v

For example instance for 2D vectors could be written as:

data V2 a = V2 a a

type instance V2 = 2
instance Vector V2 a where
  construct                = Fun V2
  inspect (V2 a b) (Fun f) = f a b

Minimal complete definition

construct, inspect

Methods

construct :: Fun (Peano (Dim v)) a (v a) Source #

N-ary function for creation of vectors.

inspect :: v a -> Fun (Peano (Dim v)) a b -> b Source #

Deconstruction of vector.

basicIndex :: v a -> Int -> a Source #

Optional more efficient implementation of indexing. Shouldn't be used directly, use ! instead.

Instances

Instances details
Vector Complex a Source # 
Instance details

Defined in Data.Vector.Fixed.Cont

Methods

construct :: Fun (Peano (Dim Complex)) a (Complex a) Source #

inspect :: Complex a ->