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
.
>>>
reifyList "xyz" (print . toList . cons 'a')
"axyz"
withCons :: SBinI b => a -> RAVec b a -> ( SBinPI ( Succ' b) => RAVec ( Succ b) a -> r) -> r Source #
head :: RAVec (' BP b) a -> a Source #
The first element of a non-empty
RAVec
.
>>>
reifyNonEmpty ('x' :| "yz") head
'x'
last :: RAVec (' BP b) a -> a Source #
The last element of a non-empty
RAVec
.
>>>
reifyNonEmpty ('x' :| "yz") last
'z'
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.
>>>
fromList "foo" :: Maybe (RAVec B.Bin3 Char)
Just (NonEmpty (NE (Cons1 (Leaf 'f') (Last (Node (Leaf 'o') (Leaf 'o'))))))
>>>
fromList "quux" :: Maybe (RAVec B.Bin3 Char)
Nothing
>>>
fromList "xy" :: Maybe (RAVec B.Bin3 Char)
Nothing
Indexing
(!) :: RAVec b a -> Pos b -> a Source #
Indexing.
>>>
let ral :: RAVec B.Bin4 Char; Just ral = fromList "abcd"
>>>
ral ! minBound
'a'
>>>
ral ! maxBound
'd'
>>>
ral ! pop top
'b'
Folds
Mapping
itraverse1 :: Apply f => ( Pos (' BP n) -> a -> f b) -> RAVec (' BP n) a -> f ( RAVec (' BP n) b) Source #
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 #
>>>
universe :: RAVec B.Bin2 (Pos B.Bin2)
NonEmpty (NE (Cons0 (Last (Node (Leaf 0) (Leaf 1)))))
>>>
let u = universe :: RAVec B.Bin3 (Pos B.Bin3)
>>>
u
NonEmpty (NE (Cons1 (Leaf 0) (Last (Node (Leaf 1) (Leaf 2)))))
>>>
P.explicitShow $ u ! Pos (PosP (Here WE))
"Pos (PosP (Here WE))"
>>>
let u' = universe :: RAVec B.Bin5 (Pos B.Bin5)
>>>
toList u' == sort (toList u')
True
repeat :: forall b a. SBinI b => a -> RAVec b a Source #
Repeat a value.
>>>
repeat 'x' :: RAVec B.Bin5 Char
NonEmpty (NE (Cons1 (Leaf 'x') (Cons0 (Last (Node (Node (Leaf 'x') (Leaf 'x')) (Node (Leaf 'x') (Leaf 'x')))))))
QuickCheck
liftShrink :: (a -> [a]) -> RAVec b a -> [ RAVec b a] Source #