Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Depth indexed perfect binary tree.
Synopsis
- data Tree (n :: Nat) a where
- singleton :: a -> Tree 'Z a
- toList :: Tree n a -> [a]
- reverse :: Tree n a -> Tree n a
- (!) :: Tree n a -> Wrd n -> a
- tabulate :: forall n a. SNatI n => (Wrd n -> a) -> Tree n a
- leftmost :: Tree n a -> a
- rightmost :: Tree n a -> a
- foldMap :: Monoid m => (a -> m) -> Tree n a -> m
- foldMap1 :: Semigroup s => (a -> s) -> Tree n a -> s
- ifoldMap :: Monoid m => (Wrd n -> a -> m) -> Tree n a -> m
- ifoldMap1 :: Semigroup s => (Wrd n -> a -> s) -> Tree n a -> s
- foldr :: (a -> b -> b) -> b -> Tree n a -> b
- ifoldr :: (Wrd n -> a -> b -> b) -> b -> Tree n a -> b
- foldr1Map :: (a -> b -> b) -> (a -> b) -> Tree n a -> b
- ifoldr1Map :: (Wrd n -> a -> b -> b) -> (Wrd n -> a -> b) -> Tree n a -> b
- foldl :: (b -> a -> b) -> b -> Tree n a -> b
- ifoldl :: (Wrd n -> b -> a -> b) -> b -> Tree n a -> b
- length :: Tree n a -> Int
- null :: Tree n a -> Bool
- sum :: Num a => Tree n a -> a
- product :: Num a => Tree n a -> a
- map :: (a -> b) -> Tree n a -> Tree n b
- imap :: (Wrd n -> a -> b) -> Tree n a -> Tree n b
- traverse :: Applicative f => (a -> f b) -> Tree n a -> f (Tree n b)
- itraverse :: Applicative f => (Wrd n -> a -> f b) -> Tree n a -> f (Tree n b)
- traverse1 :: Apply f => (a -> f b) -> Tree n a -> f (Tree n b)
- itraverse1 :: Apply f => (Wrd n -> a -> f b) -> Tree n a -> f (Tree n b)
- itraverse_ :: forall n f a b. Applicative f => (Wrd n -> a -> f b) -> Tree n a -> f ()
- zipWith :: (a -> b -> c) -> Tree n a -> Tree n b -> Tree n c
- izipWith :: (Wrd n -> a -> b -> c) -> Tree n a -> Tree n b -> Tree n c
- repeat :: SNatI n => a -> Tree n a
- universe :: SNatI n => Tree n (Wrd n)
- liftArbitrary :: forall n a. SNatI n => Gen a -> Gen (Tree n a)
- liftShrink :: forall n a. (a -> [a]) -> Tree n a -> [Tree n a]
Documentation
data Tree (n :: Nat) a where Source #
Perfectly balanced binary tree of depth n
, with 2 ^ n
elements.
Instances
SNatI n => Arbitrary1 (Tree n) Source # | |
Defined in Data.RAVec.Tree liftArbitrary :: Gen a -> Gen (Tree n a) # liftShrink :: (a -> [a]) -> Tree n a -> [Tree n a] # | |
SNatI n => Representable (Tree n) Source # | |
Foldable (Tree n) Source # | |
Defined in Data.RAVec.Tree fold :: Monoid m => Tree n m -> m # foldMap :: Monoid m => (a -> m) -> Tree n a -> m # foldMap' :: Monoid m => (a -> m) -> Tree n a -> m # foldr :: (a -> b -> b) -> b -> Tree n a -> b # foldr' :: (a -> b -> b) -> b -> Tree n a -> b # foldl :: (b -> a -> b) -> b -> Tree n a -> b # foldl' :: (b -> a -> b) -> b -> Tree n a -> b # foldr1 :: (a -> a -> a) -> Tree n a -> a # foldl1 :: (a -> a -> a) -> Tree n a -> a # elem :: Eq a => a -> Tree n a -> Bool # maximum :: Ord a => Tree n a -> a # minimum :: Ord a => Tree n a -> a # | |
Foldable1 (Tree n) Source # | |
Defined in Data.RAVec.Tree fold1 :: Semigroup m => Tree n m -> m # foldMap1 :: Semigroup m => (a -> m) -> Tree n a -> m # foldMap1' :: Semigroup m => (a -> m) -> Tree n a -> m # toNonEmpty :: Tree n a -> NonEmpty a # maximum :: Ord a => Tree n a -> a # minimum :: Ord a => Tree n a -> a # foldrMap1 :: (a -> b) -> (a -> b -> b) -> Tree n a -> b # foldlMap1' :: (a -> b) -> (b -> a -> b) -> Tree n a -> b # foldlMap1 :: (a -> b) -> (b -> a -> b) -> Tree n a -> b # foldrMap1' :: (a -> b) -> (a -> b -> b) -> Tree n a -> b # | |
Traversable (Tree n) Source # | |
SNatI n => Applicative (Tree n) Source # | |
Functor (Tree n) Source # | |
SNatI n => Distributive (Tree n) Source # | |
Apply (Tree n) Source # | |
Traversable1 (Tree n) Source # | |
FoldableWithIndex (Wrd n) (Tree n) Source # | Since: 0.2 |
Defined in Data.RAVec.Tree | |
FunctorWithIndex (Wrd n) (Tree n) Source # | Since: 0.2 |
TraversableWithIndex (Wrd n) (Tree n) Source # | Since: 0.2 |
Defined in Data.RAVec.Tree | |
(SNatI n, Arbitrary a) => Arbitrary (Tree n a) Source # | |
CoArbitrary a => CoArbitrary (Tree n a) Source # | |
Defined in Data.RAVec.Tree coarbitrary :: Tree n a -> Gen b -> Gen b # | |
(SNatI n, Function a) => Function (Tree n a) Source # | |
Semigroup a => Semigroup (Tree n a) Source # | |
Show a => Show (Tree n a) Source # | |
NFData a => NFData (Tree n a) Source # | |
Defined in Data.RAVec.Tree | |
Eq a => Eq (Tree n a) Source # | |
Ord a => Ord (Tree n a) Source # | |
Defined in Data.RAVec.Tree | |
Hashable a => Hashable (Tree n a) Source # | |
Defined in Data.RAVec.Tree | |
type Rep (Tree n) Source # | |
Defined in Data.RAVec.Tree |
Construction
singleton :: a -> Tree 'Z a Source #
Tree
of zero depth, with single element.
>>>
singleton True
Leaf True
Conversions
toList :: Tree n a -> [a] Source #
Convert Tree
to list.
>>>
toList $ Node (Node (Leaf 'a') (Leaf 'b')) (Node (Leaf 'c') (Leaf 'd'))
"abcd"
reverse :: Tree n a -> Tree n a Source #
Reverse Tree
.
>>>
let t = Node (Node (Leaf 'a') (Leaf 'b')) (Node (Leaf 'c') (Leaf 'd'))
>>>
reverse t
Node (Node (Leaf 'd') (Leaf 'c')) (Node (Leaf 'b') (Leaf 'a'))
Since: 0.1.1
Indexing
Folds
foldr :: (a -> b -> b) -> b -> Tree n a -> b Source #
>>>
foldr (:) [] $ Node (Leaf True) (Leaf False)
[True,False]
foldl :: (b -> a -> b) -> b -> Tree n a -> b Source #
>>>
foldl (flip (:)) [] $ Node (Leaf True) (Leaf False)
[False,True]
Special folds
Mapping
map :: (a -> b) -> Tree n a -> Tree n b Source #
>>>
map not $ Node (Leaf True) (Leaf False)
Node (Leaf False) (Leaf True)
imap :: (Wrd n -> a -> b) -> Tree n a -> Tree n b Source #
>>>
imap (,) $ Node (Leaf True) (Leaf False)
Node (Leaf (0b0,True)) (Leaf (0b1,False))
itraverse_ :: forall n f a b. Applicative f => (Wrd n -> a -> f b) -> Tree n a -> f () Source #
Since: 0.1.1
Zipping
izipWith :: (Wrd n -> a -> b -> c) -> Tree n a -> Tree n b -> Tree n c Source #
Zip two Tree
s. with a function that also takes the elements' indices.
repeat :: SNatI n => a -> Tree n a Source #
Repeat a value.
>>>
repeat 'x' :: Tree N.Nat2 Char
Node (Node (Leaf 'x') (Leaf 'x')) (Node (Leaf 'x') (Leaf 'x'))
Universe
QuickCheck
liftShrink :: forall n a. (a -> [a]) -> Tree n a -> [Tree n a] Source #