HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulevec-0.5.1Haskell2010

Data.Vec.Pull

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.

  • 1 type
  • 35 values
  • Packagevec-0.5.1
  • Exports36
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourcePull.hs
newtypenewtype Vec (n :: Nat) a
#

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.

Constructors

Instances16Monad, Functor, Applicative, Foldable, Foldable1, Distributive, …

Construction

2 declarations
valuesingleton :: a -> Vec ('S 'Z) a
#

Vec with exactly one element.

Example1 expression
L.fromPull $ singleton TrueTrue ::: VNil

Conversions

5 declarations
valuefromList :: SNatI n => [a] -> Maybe (Vec n a)
#

Convert list [a] to Vec n a. Returns Nothing if lengths don't match exactly.

Example1 expression
L.fromPull <$> fromList "foo" :: Maybe (L.Vec N.Nat3 Char)Just ('f' ::: 'o' ::: 'o' ::: VNil)
Example1 expression
L.fromPull <$> fromList "quux" :: Maybe (L.Vec N.Nat3 Char)Nothing
Example1 expression
L.fromPull <$> fromList "xy" :: Maybe (L.Vec N.Nat3 Char)Nothing
valuefromListPrefix :: SNatI n => [a] -> Maybe (Vec n a)
#

Convert list [a] to Vec n a. Returns Nothing if input list is too short.

Example1 expression
L.fromPull <$> fromListPrefix "foo" :: Maybe (L.Vec N.Nat3 Char)Just ('f' ::: 'o' ::: 'o' ::: VNil)
Example1 expression
L.fromPull <$> fromListPrefix "quux" :: Maybe (L.Vec N.Nat3 Char)Just ('q' ::: 'u' ::: 'u' ::: VNil)
Example1 expression
L.fromPull <$> fromListPrefix "xy" :: Maybe (L.Vec N.Nat3 Char)Nothing
valuereifyList :: [a] -> (forall (n :: Nat). SNatI n => Vec n a -> r) -> r
#

Reify any list [a] to Vec n a.

Example1 expression
reifyList "foo" length3

Indexing

8 declarations
value(!) :: Vec n a -> Fin n -> a
#

Indexing.

valuecons :: a -> Vec n a -> Vec ('S n) a
#

Cons an element in front of a Vec.

valuehead :: Vec ('S n) a -> a
#

The first element of a Vec.

Reverse

1 declaration

Folds

7 declarations
valuefoldr :: SNatI n => (a -> b -> b) -> b -> Vec n a -> b
#

Right fold.

valueifoldr :: SNatI n => (Fin n -> a -> b -> b) -> b -> Vec n a -> b
#

Right fold with an index.

valuefoldl' :: SNatI n => (b -> a -> b) -> b -> Vec n a -> b
#

Strict left fold.

Special folds

4 declarations

Mapping

2 declarations
valuemap :: (a -> b) -> Vec n a -> Vec n b
#
Example1 expression
L.fromPull $ map not $ L.toPull $ True L.::: False L.::: L.VNilFalse ::: True ::: VNil
valueimap :: (Fin n -> a -> b) -> Vec n a -> Vec n b
#
Example1 expression
L.fromPull $ imap (,) $ L.toPull $ 'a' L.::: 'b' L.::: 'c' L.::: L.VNil(0,'a') ::: (1,'b') ::: (2,'c') ::: VNil

Zipping

3 declarations
valueizipWith :: (Fin n -> a -> b -> c) -> Vec n a -> Vec n b -> Vec n c
#

Zip two Vecs. with a function that also takes the elements' indices.

Monadic

2 declarations

Universe

1 declaration
valueuniverse :: SNatI n => Vec n (Fin n)
#

Get all Fin n in a Vec n.

Example1 expression
L.fromPull (universe :: Vec N.Nat3 (Fin N.Nat3))0 ::: 1 ::: 2 ::: VNil