Safe Haskell | Safe |
---|---|
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)
- reifyList :: [a] -> (forall b. SBinI b => RAVec b a -> r) -> r
- 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
- null :: RAVec n a -> Bool
- 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
SBinI b => Arbitrary1 (RAVec b) Source # | |
Defined in Data.RAVec liftArbitrary :: Gen a -> Gen (RAVec b a) # liftShrink :: (a -> [a]) -> RAVec b a -> [RAVec b a] # | |
SBinI b => Representable (RAVec b) Source # | |
Foldable (RAVec b) Source # | |
Defined in Data.RAVec fold :: Monoid m => RAVec b m -> m # foldMap :: Monoid m => (a -> m) -> RAVec b a -> m # foldMap' :: Monoid m => (a -> m) -> RAVec b a -> m # foldr :: (a -> b0 -> b0) -> b0 -> RAVec b a -> b0 # foldr' :: (a -> b0 -> b0) -> b0 -> RAVec b a -> b0 # foldl :: (b0 -> a -> b0) -> b0 -> RAVec b a -> b0 # foldl' :: (b0 -> a -> b0) -> b0 -> RAVec b a -> b0 # foldr1 :: (a -> a -> a) -> RAVec b a -> a # foldl1 :: (a -> a -> a) -> RAVec b a -> a # elem :: Eq a => a -> RAVec b a -> Bool # maximum :: Ord a => RAVec b a -> a # minimum :: Ord a => RAVec b a -> a # | |
b ~ 'BP n => Foldable1 (RAVec b) Source # | |
Defined in Data.RAVec fold1 :: Semigroup m => RAVec b m -> m # foldMap1 :: Semigroup m => (a -> m) -> RAVec b a -> m # foldMap1' :: Semigroup m => (a -> m) -> RAVec b a -> m # toNonEmpty :: RAVec b a -> NonEmpty a # maximum :: Ord a => RAVec b a -> a # minimum :: Ord a => RAVec b a -> a # foldrMap1 :: (a -> b0) -> (a -> b0 -> b0) -> RAVec b a -> b0 # foldlMap1' :: (a -> b0) -> (b0 -> a -> b0) -> RAVec b a -> b0 # foldlMap1 :: (a -> b0) -> (b0 -> a -> b0) -> RAVec b a -> b0 # foldrMap1' :: (a -> b0) -> (a -> b0 -> b0) -> RAVec b a -> b0 # | |
Traversable (RAVec b) Source # | |
SBinI b => Applicative (RAVec b) Source # | |
Functor (RAVec b) Source # | |
SBinI b => Distributive (RAVec b) Source # | |
Apply (RAVec b) Source # | |
b ~ 'BP n => Traversable1 (RAVec b) Source # | |
FoldableWithIndex (Pos n) (RAVec n) Source # | Since: 0.2 |
Defined in Data.RAVec | |
FunctorWithIndex (Pos n) (RAVec n) Source # | Since: 0.2 |
TraversableWithIndex (Pos n) (RAVec n) Source # | Since: 0.2 |
Defined in Data.RAVec | |
(SBinI b, Arbitrary a) => Arbitrary (RAVec b a) Source # | |
CoArbitrary a => CoArbitrary (RAVec b a) Source # | |
Defined in Data.RAVec coarbitrary :: RAVec b a -> Gen b0 -> Gen b0 # | |
(SBinI b, Function a) => Function (RAVec b a) Source # | |
(Monoid a, SBinI b) => Monoid (RAVec b a) Source # | |
Semigroup a => Semigroup (RAVec b a) Source # | |
Show a => Show (RAVec b a) Source # | |
b ~ 'BZ => Boring (RAVec b a) Source # | Since: 0.2.1 |
Defined in Data.RAVec | |
NFData a => NFData (RAVec b a) Source # | |
Defined in Data.RAVec | |
Eq a => Eq (RAVec b a) Source # | |
Ord a => Ord (RAVec b a) Source # | |
Defined in Data.RAVec | |
Hashable a => Hashable (RAVec b a) Source # | |
Defined in Data.RAVec | |
type Rep (RAVec b) Source # | |
Defined in Data.RAVec |
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"
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 aNothing
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
reifyList :: [a] -> (forall b. SBinI b => RAVec b a -> r) -> r Source #
>>>
reifyList "foo" print
NonEmpty (NE (Cons1 (Leaf 'f') (Last (Node (Leaf 'o') (Leaf 'o')))))
>>>
reifyList "xyzzy" toList
"xyzzy"
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
Special 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 #