HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulevec-0.5.1.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.

Contents
  1. Construction
  2. Conversions
  3. Indexing
  4. Reverse
  5. Folds
  6. Special folds
  7. Mapping
  8. Zipping
  9. Monadic
  10. Universe
Synopsis
  • Packagevec-0.5.1.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

valuesingleton :: a -> Vec ('S 'Z) a

Vec with exactly one element.

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

Conversions

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

Reverse

Folds

Special folds

Mapping

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

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

Universe

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