Safe Haskell | None |
---|---|
Language | Haskell2010 |
Depth indexed perfect binary tree.
Synopsis
- data Tree (n :: Nat ) a where
- singleton :: a -> Tree ' Z a
- toList :: Tree n a -> [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
- 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)
- 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
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"
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]
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))
Zipping
zipWith :: (a -> b -> c) -> Tree n a -> Tree n b -> Tree n c Source #
Zip two
Vec
s with a function.
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 #