Safe Haskell | Safe-Infered |
---|
This module defines a class of Vectors over types with Equality, along with an instance of this class using lists of pairs. In the context of QIO, these Vectors are used to hold the amplitudes of various basis-states within a superposition.
- class VecEq v where
- newtype VecEqL x a = VecEqL {
- unVecEqL :: [(a, x)]
- vEqZero :: VecEqL x a
- add :: (Eq a, Num x) => (a, x) -> VecEqL x a -> VecEqL x a
- vEqPlus :: (Eq a, Num x) => VecEqL x a -> VecEqL x a -> VecEqL x a
- vEqTimes :: (Num x, Eq x) => x -> VecEqL x a -> VecEqL x a
- vEqAt :: (Eq a, Num x) => a -> VecEqL x a -> x
- class EqMonad m where
- data AsMonad m a where
- unEmbed :: Eq a => AsMonad m a -> m a
Documentation
Any type that fulfills this type class is a Vector over types with equality
An empty instance of the vector
(<+>) :: (Eq a, Num x) => v x a -> v x a -> v x aSource
Two Vectors can be combined
(<*>) :: (Num x, Eq x) => x -> v x a -> v x aSource
A Vector can be multiplied by a scalar
(<@>) :: (Eq a, Num x) => a -> v x a -> xSource
The amplitude of a given element can be accessed
fromList :: [(a, x)] -> v x aSource
The vector can be created from a list of pairs
toList :: v x a -> [(a, x)]Source
The cevtor can be converted into a list of pairs
This type is a wrapper around a list of pairs.
add :: (Eq a, Num x) => (a, x) -> VecEqL x a -> VecEqL x aSource
A basis state with the given amplitude can be added to a VecEqL by adding the amplitudes if the state is already in the vector, or by inserting the base state if it isn't already in the vector.
vEqPlus :: (Eq a, Num x) => VecEqL x a -> VecEqL x a -> VecEqL x aSource
Combining two vectors is achieved by folding the add operation over the second vector
vEqTimes :: (Num x, Eq x) => x -> VecEqL x a -> VecEqL x aSource
Scalar multiplcation is achieved by mapping the multiplication over each pair in the vector. Multiplication by 0 is a special case, and will remove all the basis states from the vector.
vEqAt :: (Eq a, Num x) => a -> VecEqL x a -> xSource
The amplitude of an element can be found by looking through each element until the matchinf one is found.
An EqMonad is a monad that has Return and Bind operations that depend on the type in the monad being a member of the Eq class