type-unary-0.1.8: Type-level and typed unary natural numbers, vectors, inequality proofs

Stability experimental conal@conal.net

TypeUnary.Vec

Description

Experiment in length-typed vectors

Synopsis

# Type-level numbers

data Z Source

Type-level representation of zero

Instances

 IsNat Z

data S n Source

Type-level representation of successor

Instances

 IsNat n => IsNat (S n)

type family a :+: b Source

Sum of type-level numbers

type N0 = ZSource

type N1 = S N0Source

type N2 = S N1Source

type N3 = S N2Source

type N4 = S N3Source

type N5 = S N4Source

type N6 = S N5Source

type N7 = S N6Source

type N8 = S N7Source

type N9 = S N8Source

type N10 = S N9Source

type N11 = S N10Source

type N12 = S N11Source

type N13 = S N12Source

type N14 = S N13Source

type N15 = S N14Source

type N16 = S N15Source

# Typed natural numbers

data Nat whereSource

Constructors

 Zero :: Nat Z Succ :: IsNat n => Nat n -> Nat (S n)

Instances

 Show (Nat n)

withIsNat :: (IsNat n => Nat n -> a) -> Nat n -> aSource

natSucc :: Nat n -> Nat (S n)Source

natIsNat :: Nat n -> IsNat n => Nat nSource

natToZ :: Nat n -> IntegerSource

Interpret a `Nat` as an `Integer`

natEq :: Nat m -> Nat n -> Maybe (m :=: n)Source

Equality test

natAdd :: Nat m -> Nat n -> Nat (m :+: n)Source

Sum of naturals

data m :<: n Source

Proof that `m < n`

data Index lim Source

A number under the given limit, with proof

Constructors

 forall n . IsNat n => Index (n :<: lim) (Nat n)

Instances

 Eq (Index lim)

succI :: Index m -> Index (S m)Source

# Vectors

data Vec whereSource

Vectors with type-determined length, having empty vector (`ZVec`) and vector cons ('(:<)').

Constructors

 ZVec :: Vec Z a :< :: a -> Vec n a -> Vec (S n) a

Instances

 IsNat n => Monad (Vec n) Functor (Vec n) IsNat n => Applicative (Vec n) Foldable (Vec n) Traversable (Vec n) Eq a => Eq (Vec n a) Ord a => Ord (Vec n a) Show a => Show (Vec n a) (IsNat n, Storable a) => Storable (Vec n a) (IsNat n, Num a) => VectorSpace (Vec n a) (IsNat n, Num a) => InnerSpace (Vec n a) (IsNat n, Num a) => AdditiveGroup (Vec n a) ToVec (Vec n a) n a

headV :: Vec (S n) a -> aSource

tailV :: Vec (S n) a -> Vec n aSource

Type-safe tail for vectors

joinV :: Vec n (Vec n a) -> Vec n aSource

Equivalent to monad `join` for vectors

class IsNat n whereSource

`n` a vector length.

Methods

nat :: Nat nSource

pureV :: a -> Vec n aSource

elemsV :: [a] -> Vec n aSource

peekV :: Storable a => Ptr a -> IO (Vec n a)Source

pokeV :: Storable a => Ptr a -> Vec n a -> IO ()Source

Instances

 IsNat Z IsNat n => IsNat (S n)

(<+>) :: Vec m a -> Vec n a -> Vec (m :+: n) aSource

Concatenation of vectors

indices :: Nat n -> Vec n (Index n)Source

Indices under `n`: `index0` :< `index1` :< ...

vec1 :: a -> Vec1 aSource

vec2 :: a -> a -> Vec2 aSource

vec3 :: a -> a -> a -> Vec3 aSource

vec4 :: a -> a -> a -> a -> Vec4 aSource

vec5 :: a -> a -> a -> a -> a -> Vec5 aSource

vec6 :: a -> a -> a -> a -> a -> a -> Vec6 aSource

vec7 :: a -> a -> a -> a -> a -> a -> a -> Vec7 aSource

vec8 :: a -> a -> a -> a -> a -> a -> a -> a -> Vec8 aSource

un1 :: Vec1 a -> aSource

Extract element

un2 :: Vec2 a -> (a, a)Source

Extract elements

un3 :: Vec3 a -> (a, a, a)Source

Extract elements

un4 :: Vec4 a -> (a, a, a, a)Source

Extract elements

get :: Index n -> Vec n a -> aSource

General indexing, taking a proof that the index is within bounds.

Arguments

 :: Vec (N1 :+: n) a -> a Get first element

Arguments

 :: Vec (N2 :+: n) a -> a Get second element

Arguments

 :: Vec (N3 :+: n) a -> a Get third element

Arguments

 :: Vec (N4 :+: n) a -> a Get fourth element

swizzle :: Vec n (Index m) -> Vec m a -> Vec n aSource

Swizzling. Extract multiple elements simultaneously.

split :: IsNat n => Vec (n :+: m) a -> (Vec n a, Vec m a)Source

Split a vector

deleteV :: Eq a => a -> Vec (S n) a -> Vec n aSource

Delete exactly one occurrence of an element from a vector, raising an error if the element isn't present.

class ToVec c n a whereSource

Methods

toVec :: c -> Vec n aSource

Instances

 IsNat n => ToVec [a] n a ToVec (Vec n a) n a