Safe Haskell | None |
---|---|
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]
- fromList :: SNatI n => [a] -> Maybe (Vec n a)
- _Vec :: SNatI n => Prism' [a] (Vec n a)
- fromListPrefix :: SNatI n => [a] -> Maybe (Vec n a)
- reifyList :: [a] -> (forall n. InlineInduction n => Vec n a -> r) -> r
- (!) :: Vec n a -> Fin n -> a
- ix :: Fin n -> Lens' (Vec n a) a
- _Cons :: Iso (Vec (S n) a) (Vec (S n) b) (a, Vec n a) (b, Vec n b)
- _head :: Lens' (Vec (S n) a) a
- _tail :: Lens' (Vec (S n) a) (Vec n a)
- head :: Vec (S n) a -> a
- tail :: Vec (S 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
- 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 unpurpose don't have bad (fusion-wise) instances, like Traversable
.
Generally, there aren't functions which would be bad consumers or bad producers.
Instances
Monad (Vec n) Source # | |
Functor (Vec n) Source # | |
Applicative (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 # 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 # | |
Distributive (Vec n) Source # | |
Representable (Vec n) Source # | |
Apply (Vec n) Source # | |
Bind (Vec n) Source # | |
FunctorWithIndex (Fin n) (Vec n) Source # | |
SNatI n => FoldableWithIndex (Fin n) (Vec n) Source # | |
(Eq a, SNatI n) => Eq (Vec n a) Source # | |
Semigroup a => Semigroup (Vec n a) Source # | |
Monoid a => Monoid (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. InlineInduction n => Vec n a -> r) -> r Source #
Reify any list [a]
to
.Vec
n a
>>>
reifyList "foo" length
3
Indexing
ix :: Fin n -> Lens' (Vec n a) a Source #
Index lens.
>>>
('a' L.::: 'b' L.::: 'c' L.::: L.VNil) ^. L._Pull . ix (FS FZ)
'b'
>>>
('a' L.::: 'b' L.::: 'c' L.::: L.VNil) & L._Pull . ix (FS FZ) .~ 'x'
'a' ::: 'x' ::: 'c' ::: VNil
_head :: Lens' (Vec (S n) a) a Source #
Head lens. Note: lens
_head
is a Traversal'
.
>>>
('a' L.::: 'b' L.::: 'c' L.::: L.VNil) ^. L._Pull . _head
'a'
>>>
('a' L.::: 'b' L.::: 'c' L.::: L.VNil) & L._Pull . _head .~ 'x'
'x' ::: 'b' ::: 'c' ::: VNil
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 #
>>>
over L._Pull (map not) (True L.::: False L.::: L.VNil)
False ::: True ::: VNil
imap :: (Fin n -> a -> b) -> Vec n a -> Vec n b Source #
>>>
over L._Pull (imap (,)) ('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.