module FP.Prelude.Vector
( module FP.Prelude.Vector
, module Data.Vector.Unboxed
) where
import FP.Prelude.Core
import Data.Vector.Unboxed (Unbox)
import qualified Data.Vector as Vector
import qualified Data.Vector.Unboxed as UVector
type ๐ = Vector.Vector
instance Monoid (๐ a) where {null = Vector.empty;(โงบ) = (Vector.++)}
instance ToStream a (๐ a) where stream = stream โ Vector.toList
instance ToFold a (๐ a) where fold = fold โ stream
instance Lookup โ a (๐ a) where lookup n v = v Vector.!? ๐ n
vec โท (ToFold a t) โ t โ ๐ a
vec = Vector.fromList โ list
type ๐แต = UVector.Vector
instance (Unbox a) โ Monoid (๐แต a) where {null = UVector.empty;(โงบ) = (UVector.++)}
instance (Unbox a) โ ToStream a (๐แต a) where stream = stream โ UVector.toList
instance (Unbox a) โ ToFold a (๐แต a) where fold = fold โ stream
instance (Unbox a) โ Lookup โ a (๐แต a) where lookup n v = v UVector.!? ๐ n
uvec โท (ToFold a t,Unbox a) โ t โ ๐แต a
uvec = UVector.fromList โ list
data ๐ a = Matrix
{ matrixRowSize โท โ
, matrixData โท ๐ a
}
instance Lookup (โ,โ) a (๐ a) where
lookup (i,j) (Matrix rowSize dat) = dat # (i ร rowSize + j)
matrix โท (ToFold a t) โ โ โ t โ ๐ a
matrix n = Matrix n โ vec
data ๐แต a = UMatrix
{ umatrixRowSize โท โ
, umatrixData โท ๐แต a
}
instance (Unbox a) โ Lookup (โ,โ) a (๐แต a) where
lookup (i,j) (UMatrix rowSize dat) = dat # (i ร rowSize + j)
umatrix โท (ToFold a t,Unbox a) โ โ โ t โ ๐แต a
umatrix n = UMatrix n โ uvec