Safe Haskell | None |
---|---|

Language | Haskell2010 |

Length-indexed random access list.

See http://www.staff.science.uu.nl/~swier004/publications/2019-jfp-submission.pdf

## Synopsis

- data RAVec (b :: Bin) a where
- empty :: RAVec Bin0 a
- singleton :: a -> RAVec Bin1 a
- cons :: a -> RAVec b a -> RAVec (Succ b) a
- withCons :: SBinI b => a -> RAVec b a -> (SBinPI (Succ' b) => RAVec (Succ b) a -> r) -> r
- head :: RAVec (BP b) a -> a
- last :: RAVec (BP b) a -> a
- toList :: RAVec b a -> [a]
- toNonEmpty :: RAVec (BP b) a -> NonEmpty a
- fromList :: forall b a. SBinI b => [a] -> Maybe (RAVec b a)
- reifyNonEmpty :: NonEmpty a -> (forall b. SBinPI b => RAVec (BP b) a -> r) -> r
- (!) :: RAVec b a -> Pos b -> a
- tabulate :: forall b a. SBinI b => (Pos b -> a) -> RAVec b a
- foldMap :: Monoid m => (a -> m) -> RAVec n a -> m
- foldMap1 :: Semigroup m => (a -> m) -> RAVec (BP b) a -> m
- ifoldMap :: Monoid m => (Pos b -> a -> m) -> RAVec b a -> m
- ifoldMap1 :: Semigroup m => (Pos (BP b) -> a -> m) -> RAVec (BP b) a -> m
- foldr :: (a -> b -> b) -> b -> RAVec n a -> b
- ifoldr :: (Pos n -> a -> b -> b) -> b -> RAVec n a -> b
- map :: (a -> b) -> RAVec n a -> RAVec n b
- imap :: (Pos n -> a -> b) -> RAVec n a -> RAVec n b
- traverse :: Applicative f => (a -> f b) -> RAVec n a -> f (RAVec n b)
- itraverse :: Applicative f => (Pos n -> a -> f b) -> RAVec n a -> f (RAVec n b)
- traverse1 :: Apply f => (a -> f b) -> RAVec (BP n) a -> f (RAVec (BP n) b)
- itraverse1 :: Apply f => (Pos (BP n) -> a -> f b) -> RAVec (BP n) a -> f (RAVec (BP n) b)
- zipWith :: (a -> b -> c) -> RAVec n a -> RAVec n b -> RAVec n c
- izipWith :: (Pos n -> a -> b -> c) -> RAVec n a -> RAVec n b -> RAVec n c
- universe :: forall b. SBinI b => RAVec b (Pos b)
- repeat :: forall b a. SBinI b => a -> RAVec b a
- liftArbitrary :: SBinI b => Gen a -> Gen (RAVec b a)
- liftShrink :: (a -> [a]) -> RAVec b a -> [RAVec b a]

# Random access list

data RAVec (b :: Bin) a where Source #

Length indexed random access lists.

## Instances

# Construction

cons :: a -> RAVec b a -> RAVec (Succ b) a Source #

Cons an element in front of `RAVec`

.

`>>>`

"axyz"`reifyList "xyz" (print . toList . cons 'a')`

head :: RAVec (BP b) a -> a Source #

The first element of a non-empty `RAVec`

.

`>>>`

'x'`reifyNonEmpty ('x' :| "yz") head`

last :: RAVec (BP b) a -> a Source #

The last element of a non-empty `RAVec`

.

`>>>`

'z'`reifyNonEmpty ('x' :| "yz") last`

# Conversion

fromList :: forall b a. SBinI b => [a] -> Maybe (RAVec b a) Source #

Convert a list `[a]`

to

.
Returns `RAVec`

b a`Nothing`

if lengths don't match.

`>>>`

Just (NonEmpty (NE (Cons1 (Leaf 'f') (Last (Node (Leaf 'o') (Leaf 'o'))))))`fromList "foo" :: Maybe (RAVec B.Bin3 Char)`

`>>>`

Nothing`fromList "quux" :: Maybe (RAVec B.Bin3 Char)`

`>>>`

Nothing`fromList "xy" :: Maybe (RAVec B.Bin3 Char)`

# Indexing

(!) :: RAVec b a -> Pos b -> a Source #

Indexing.

`>>>`

`let ral :: RAVec B.Bin4 Char; Just ral = fromList "abcd"`

`>>>`

'a'`ral ! minBound`

`>>>`

'd'`ral ! maxBound`

`>>>`

'b'`ral ! pop top`

# Folds

# Mapping

# Zipping

zipWith :: (a -> b -> c) -> RAVec n a -> RAVec n b -> RAVec n c Source #

Zip two `RAVec`

s with a function.

# Universe

universe :: forall b. SBinI b => RAVec b (Pos b) Source #

`>>>`

NonEmpty (NE (Cons0 (Last (Node (Leaf 0) (Leaf 1)))))`universe :: RAVec B.Bin2 (Pos B.Bin2)`

`>>>`

`let u = universe :: RAVec B.Bin3 (Pos B.Bin3)`

`>>>`

NonEmpty (NE (Cons1 (Leaf 0) (Last (Node (Leaf 1) (Leaf 2)))))`u`

`>>>`

"Pos (PosP (Here WE))"`P.explicitShow $ u ! Pos (PosP (Here WE))`

`>>>`

`let u' = universe :: RAVec B.Bin5 (Pos B.Bin5)`

`>>>`

True`toList u' == sort (toList u')`

repeat :: forall b a. SBinI b => a -> RAVec b a Source #

Repeat a value.

`>>>`

NonEmpty (NE (Cons1 (Leaf 'x') (Cons0 (Last (Node (Node (Leaf 'x') (Leaf 'x')) (Node (Leaf 'x') (Leaf 'x')))))))`repeat 'x' :: RAVec B.Bin5 Char`

# QuickCheck

liftShrink :: (a -> [a]) -> RAVec b a -> [RAVec b a] Source #