Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Pull/representable
.Vec
n a = Fin
n -> a
The module tries to have same API as Data.Vec.Lazy, missing bits:
withDict
, toPull
, fromPull
, traverse
(and variants),
(++)
, concat
and split
.
Synopsis
- newtype Vec n a = Vec {}
- empty :: Vec 'Z a
- singleton :: a -> Vec ('S 'Z) a
- toList :: SNatI n => Vec n a -> [a]
- toNonEmpty :: SNatI n => Vec ('S n) a -> NonEmpty a
- fromList :: SNatI n => [a] -> Maybe (Vec n a)
- fromListPrefix :: SNatI n => [a] -> Maybe (Vec n a)
- reifyList :: [a] -> (forall n. SNatI n => Vec n a -> r) -> r
- (!) :: Vec n a -> Fin n -> a
- tabulate :: (Fin n -> a) -> Vec n a
- cons :: a -> Vec n a -> Vec ('S n) a
- snoc :: forall a n. SNatI n => Vec n a -> a -> Vec ('S n) a
- head :: Vec ('S n) a -> a
- last :: forall n a. SNatI n => Vec ('S n) a -> a
- tail :: Vec ('S n) a -> Vec n a
- init :: forall n a. SNatI n => Vec ('S n) a -> Vec n a
- reverse :: forall n a. SNatI n => Vec n a -> Vec n a
- foldMap :: (Monoid m, SNatI n) => (a -> m) -> Vec n a -> m
- foldMap1 :: (Semigroup s, SNatI n) => (a -> s) -> Vec ('S n) a -> s
- ifoldMap :: (Monoid m, SNatI n) => (Fin n -> a -> m) -> Vec n a -> m
- ifoldMap1 :: (Semigroup s, SNatI n) => (Fin ('S n) -> a -> s) -> Vec ('S n) a -> s
- foldr :: SNatI n => (a -> b -> b) -> b -> Vec n a -> b
- ifoldr :: SNatI n => (Fin n -> a -> b -> b) -> b -> Vec n a -> b
- foldl' :: SNatI n => (b -> a -> b) -> b -> Vec n a -> b
- length :: forall n a. SNatI n => Vec n a -> Int
- null :: forall n a. SNatI n => Vec n a -> Bool
- sum :: (Num a, SNatI n) => Vec n a -> a
- product :: (Num a, SNatI n) => Vec n a -> a
- map :: (a -> b) -> Vec n a -> Vec n b
- imap :: (Fin n -> a -> b) -> Vec n a -> Vec n b
- zipWith :: (a -> b -> c) -> Vec n a -> Vec n b -> Vec n c
- izipWith :: (Fin n -> a -> b -> c) -> Vec n a -> Vec n b -> Vec n c
- repeat :: x -> Vec n x
- bind :: Vec n a -> (a -> Vec n b) -> Vec n b
- join :: Vec n (Vec n a) -> Vec n a
- universe :: SNatI n => Vec n (Fin n)
Documentation
Easily fuseable Vec
.
It on purpose doesn't have bad (fusion-wise) instances, like Traversable
.
Generally, there aren't functions which would be bad consumers or bad producers.
Instances
Representable (Vec n) Source # | |
SNatI n => Foldable (Vec n) Source # | |
Defined in Data.Vec.Pull fold :: Monoid m => Vec n m -> m # foldMap :: Monoid m => (a -> m) -> Vec n a -> m # foldMap' :: Monoid m => (a -> m) -> Vec n a -> m # foldr :: (a -> b -> b) -> b -> Vec n a -> b # foldr' :: (a -> b -> b) -> b -> Vec n a -> b # foldl :: (b -> a -> b) -> b -> Vec n a -> b # foldl' :: (b -> a -> b) -> b -> Vec n a -> b # foldr1 :: (a -> a -> a) -> Vec n a -> a # foldl1 :: (a -> a -> a) -> Vec n a -> a # elem :: Eq a => a -> Vec n a -> Bool # maximum :: Ord a => Vec n a -> a # minimum :: Ord a => Vec n a -> a # | |
(SNatI m, n ~ 'S m) => Foldable1 (Vec n) Source # | |
Defined in Data.Vec.Pull fold1 :: Semigroup m => Vec n m -> m # foldMap1 :: Semigroup m => (a -> m) -> Vec n a -> m # foldMap1' :: Semigroup m => (a -> m) -> Vec n a -> m # toNonEmpty :: Vec n a -> NonEmpty a # maximum :: Ord a => Vec n a -> a # minimum :: Ord a => Vec n a -> a # foldrMap1 :: (a -> b) -> (a -> b -> b) -> Vec n a -> b # foldlMap1' :: (a -> b) -> (b -> a -> b) -> Vec n a -> b # foldlMap1 :: (a -> b) -> (b -> a -> b) -> Vec n a -> b # foldrMap1' :: (a -> b) -> (a -> b -> b) -> Vec n a -> b # | |
Applicative (Vec n) Source # | |
Functor (Vec n) Source # | |
Monad (Vec n) Source # | |
Distributive (Vec n) Source # | |
Apply (Vec n) Source # | |
Bind (Vec n) Source # | |
SNatI n => FoldableWithIndex (Fin n) (Vec n) Source # | Since: 0.4 |
Defined in Data.Vec.Pull | |
FunctorWithIndex (Fin n) (Vec n) Source # | Since: 0.4 |
Monoid a => Monoid (Vec n a) Source # | |
Semigroup a => Semigroup (Vec n a) Source # | |
n ~ 'Z => Boring (Vec n a) Source # | Since: 0.4.1 |
Defined in Data.Vec.Pull | |
(Eq a, SNatI n) => Eq (Vec n a) Source # | |
type Rep (Vec n) Source # | |
Defined in Data.Vec.Pull |
Construction
singleton :: a -> Vec ('S 'Z) a Source #
Vec
with exactly one element.
>>>
L.fromPull $ singleton True
True ::: VNil
Conversions
fromList :: SNatI n => [a] -> Maybe (Vec n a) Source #
Convert list [a]
to
.
Returns Vec
n aNothing
if lengths don't match exactly.
>>>
L.fromPull <$> fromList "foo" :: Maybe (L.Vec N.Nat3 Char)
Just ('f' ::: 'o' ::: 'o' ::: VNil)
>>>
L.fromPull <$> fromList "quux" :: Maybe (L.Vec N.Nat3 Char)
Nothing
>>>
L.fromPull <$> fromList "xy" :: Maybe (L.Vec N.Nat3 Char)
Nothing
fromListPrefix :: SNatI n => [a] -> Maybe (Vec n a) Source #
Convert list [a]
to
.
Returns Vec
n aNothing
if input list is too short.
>>>
L.fromPull <$> fromListPrefix "foo" :: Maybe (L.Vec N.Nat3 Char)
Just ('f' ::: 'o' ::: 'o' ::: VNil)
>>>
L.fromPull <$> fromListPrefix "quux" :: Maybe (L.Vec N.Nat3 Char)
Just ('q' ::: 'u' ::: 'u' ::: VNil)
>>>
L.fromPull <$> fromListPrefix "xy" :: Maybe (L.Vec N.Nat3 Char)
Nothing
reifyList :: [a] -> (forall n. SNatI n => Vec n a -> r) -> r Source #
Reify any list [a]
to
.Vec
n a
>>>
reifyList "foo" length
3
Indexing
snoc :: forall a n. SNatI n => Vec n a -> a -> Vec ('S n) a Source #
Add a single element at the end of a Vec
.
Since: 0.2.1
Reverse
Folds
ifoldMap1 :: (Semigroup s, SNatI n) => (Fin ('S n) -> a -> s) -> Vec ('S n) a -> s Source #
There is no type-class for this :(
Special folds
Mapping
map :: (a -> b) -> Vec n a -> Vec n b Source #
>>>
L.fromPull $ map not $ L.toPull $ True L.::: False L.::: L.VNil
False ::: True ::: VNil
imap :: (Fin n -> a -> b) -> Vec n a -> Vec n b Source #
>>>
L.fromPull $ imap (,) $ L.toPull $ 'a' L.::: 'b' L.::: 'c' L.::: L.VNil
(0,'a') ::: (1,'b') ::: (2,'c') ::: VNil
Zipping
izipWith :: (Fin n -> a -> b -> c) -> Vec n a -> Vec n b -> Vec n c Source #
Zip two Vec
s. with a function that also takes the elements' indices.