Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Depth indexed perfect tree as data family.
Synopsis
- data family Tree (n :: Nat) a
- singleton :: a -> Tree 'Z a
- toList :: forall n a. SNatI n => Tree n a -> [a]
- reverse :: forall n a. SNatI n => Tree n a -> Tree n a
- (!) :: SNatI n => Tree n a -> Wrd n -> a
- tabulate :: SNatI n => (Wrd n -> a) -> Tree n a
- leftmost :: SNatI n => Tree n a -> a
- rightmost :: SNatI n => Tree n a -> a
- foldMap :: forall a n m. (Monoid m, SNatI n) => (a -> m) -> Tree n a -> m
- foldMap1 :: forall s a n. (Semigroup s, SNatI n) => (a -> s) -> Tree n a -> s
- ifoldMap :: forall a n m. (Monoid m, SNatI n) => (Wrd n -> a -> m) -> Tree n a -> m
- ifoldMap1 :: forall a n s. (Semigroup s, SNatI n) => (Wrd ('S n) -> a -> s) -> Tree ('S n) a -> s
- foldr :: forall a b n. SNatI n => (a -> b -> b) -> b -> Tree n a -> b
- ifoldr :: forall a b n. SNatI n => (Wrd n -> a -> b -> b) -> b -> Tree n a -> b
- foldr1Map :: forall a b n. SNatI n => (a -> b -> b) -> (a -> b) -> Tree n a -> b
- ifoldr1Map :: (Wrd n -> a -> b -> b) -> (Wrd n -> a -> b) -> Tree n a -> b
- foldl :: forall a b n. SNatI n => (b -> a -> b) -> b -> Tree n a -> b
- ifoldl :: forall a b n. SNatI n => (Wrd n -> b -> a -> b) -> b -> Tree n a -> b
- length :: forall n a. SNatI n => Tree n a -> Int
- null :: Tree n a -> Bool
- sum :: (Num a, SNatI n) => Tree n a -> a
- product :: (Num a, SNatI n) => Tree n a -> a
- map :: forall a b n. SNatI n => (a -> b) -> Tree n a -> Tree n b
- imap :: SNatI n => (Wrd n -> a -> b) -> Tree n a -> Tree n b
- traverse :: forall n f a b. (Applicative f, SNatI n) => (a -> f b) -> Tree n a -> f (Tree n b)
- itraverse :: forall n f a b. (Applicative f, SNatI n) => (Wrd n -> a -> f b) -> Tree n a -> f (Tree n b)
- traverse1 :: forall n f a b. (Apply f, SNatI n) => (a -> f b) -> Tree n a -> f (Tree n b)
- itraverse1 :: forall n f a b. (Apply f, SNatI n) => (Wrd n -> a -> f b) -> Tree n a -> f (Tree n b)
- itraverse_ :: forall n f a b. (Applicative f, SNatI n) => (Wrd n -> a -> f b) -> Tree n a -> f ()
- zipWith :: forall a b c n. SNatI n => (a -> b -> c) -> Tree n a -> Tree n b -> Tree n c
- izipWith :: SNatI n => (Wrd n -> a -> b -> c) -> Tree n a -> Tree n b -> Tree n c
- repeat :: SNatI n => x -> Tree n x
- universe :: SNatI n => Tree n (Wrd n)
- liftArbitrary :: forall n a. SNatI n => Gen a -> Gen (Tree n a)
- liftShrink :: forall n a. SNatI n => (a -> [a]) -> Tree n a -> [Tree n a]
- ensureSpine :: SNatI n => Tree n a -> Tree n a
Documentation
data family Tree (n :: Nat) a Source #
Instances
SNatI n => Arbitrary1 (Tree n) Source # | |
Defined in Data.RAVec.Tree.DF liftArbitrary :: Gen a -> Gen (Tree n a) # liftShrink :: (a -> [a]) -> Tree n a -> [Tree n a] # | |
SNatI n => Representable (Tree n) Source # | |
SNatI n => Foldable (Tree n) Source # | |
Defined in Data.RAVec.Tree.DF 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 # | |
SNatI n => Foldable1 (Tree n) Source # | |
Defined in Data.RAVec.Tree.DF 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 # | |
SNatI n => Traversable (Tree n) Source # | |
SNatI n => Applicative (Tree n) Source # | |
SNatI n => Functor (Tree n) Source # | |
SNatI n => Distributive (Tree n) Source # | |
SNatI n => Apply (Tree n) Source # | |
SNatI n => Traversable1 (Tree n) Source # | |
SNatI n => FoldableWithIndex (Wrd n) (Tree n) Source # | Since: 0.2 |
Defined in Data.RAVec.Tree.DF | |
SNatI n => FunctorWithIndex (Wrd n) (Tree n) Source # | Since: 0.2 |
SNatI n => TraversableWithIndex (Wrd n) (Tree n) Source # | Since: 0.2 |
Defined in Data.RAVec.Tree.DF | |
(SNatI n, Arbitrary a) => Arbitrary (Tree n a) Source # | |
(SNatI n, CoArbitrary a) => CoArbitrary (Tree n a) Source # | |
Defined in Data.RAVec.Tree.DF coarbitrary :: Tree n a -> Gen b -> Gen b # | |
(SNatI n, Function a) => Function (Tree n a) Source # | |
(Monoid a, SNatI n) => Monoid (Tree n a) Source # | |
(Semigroup a, SNatI n) => Semigroup (Tree n a) Source # | |
(Show a, SNatI n) => Show (Tree n a) Source # | |
(NFData a, SNatI n) => NFData (Tree n a) Source # | |
Defined in Data.RAVec.Tree.DF | |
(Eq a, SNatI n) => Eq (Tree n a) Source # | |
(Ord a, SNatI n) => Ord (Tree n a) Source # | |
Defined in Data.RAVec.Tree.DF | |
(Hashable a, SNatI n) => Hashable (Tree n a) Source # | |
Defined in Data.RAVec.Tree.DF | |
newtype Tree 'Z a Source # | |
Defined in Data.RAVec.Tree.DF | |
type Rep (Tree n) Source # | |
Defined in Data.RAVec.Tree.DF | |
data Tree ('S n) a Source # | |
Construction
Conversions
toList :: forall n a. SNatI n => Tree n a -> [a] Source #
Convert Tree
to list.
>>>
toList $ Node (Node (Leaf 'f') (Leaf 'o')) (Node (Leaf 'o') (Leaf 'd'))
"food"
reverse :: forall n a. SNatI n => 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'))
Indexing
(!) :: SNatI n => Tree n a -> Wrd n -> a Source #
Indexing.
>>>
let t = Node (Node (Leaf 'a') (Leaf 'b')) (Node (Leaf 'c') (Leaf 'd'))
>>>
t ! W1 (W0 WE)
'c'
tabulate :: SNatI n => (Wrd n -> a) -> Tree n a Source #
Tabulating, inverse of !
.
>>>
tabulate id :: Tree N.Nat2 (Wrd N.Nat2)
Node (Node (Leaf 0b00) (Leaf 0b01)) (Node (Leaf 0b10) (Leaf 0b11))
Folds
foldMap1 :: forall s a n. (Semigroup s, SNatI n) => (a -> s) -> Tree n a -> s Source #
See Foldable1
.
ifoldMap :: forall a n m. (Monoid m, SNatI n) => (Wrd n -> a -> m) -> Tree n a -> m Source #
See FoldableWithIndex
.
ifoldMap1 :: forall a n s. (Semigroup s, SNatI n) => (Wrd ('S n) -> a -> s) -> Tree ('S n) a -> s Source #
There is no type-class for this :(
ifoldr :: forall a b n. SNatI n => (Wrd n -> a -> b -> b) -> b -> Tree n a -> b Source #
Right fold with an index.
ifoldl :: forall a b n. SNatI n => (Wrd n -> b -> a -> b) -> b -> Tree n a -> b Source #
Left fold with an index.
Special folds
Mapping
map :: forall a b n. SNatI n => (a -> b) -> Tree n a -> Tree n b Source #
>>>
map not $ Node (Leaf True) (Leaf False)
Node (Leaf False) (Leaf True)
imap :: SNatI n => (Wrd n -> a -> b) -> Tree n a -> Tree n b Source #
>>>
let t = Node (Node (Leaf 'a') (Leaf 'b')) (Node (Leaf 'c') (Leaf 'd'))
>>>
imap (,) t
Node (Node (Leaf (0b00,'a')) (Leaf (0b01,'b'))) (Node (Leaf (0b10,'c')) (Leaf (0b11,'d')))
traverse :: forall n f a b. (Applicative f, SNatI n) => (a -> f b) -> Tree n a -> f (Tree n b) Source #
itraverse :: forall n f a b. (Applicative f, SNatI n) => (Wrd n -> a -> f b) -> Tree n a -> f (Tree n b) Source #
itraverse1 :: forall n f a b. (Apply f, SNatI n) => (Wrd n -> a -> f b) -> Tree n a -> f (Tree n b) Source #
itraverse_ :: forall n f a b. (Applicative f, SNatI n) => (Wrd n -> a -> f b) -> Tree n a -> f () Source #
Apply an action to every element of a Tree
and its index, ignoring the results.
Zipping
zipWith :: forall a b c n. SNatI n => (a -> b -> c) -> Tree n a -> Tree n b -> Tree n c Source #
Zip two Tree
s with a function.
izipWith :: SNatI n => (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 => x -> Tree n x Source #
Repeat value
>>>
repeat 'x' :: Tree N.Nat2 Char
Node (Node (Leaf 'x') (Leaf 'x')) (Node (Leaf 'x') (Leaf 'x'))
Universe
QuickCheck
Ensure spine
ensureSpine :: SNatI n => Tree n a -> Tree n a Source #
Ensure spine.
If we have an undefined Tree
,
>>>
let v = error "err" :: Tree N.Nat2 Char
And insert data into it later:
>>>
let setHead :: a -> Tree N.Nat2 a -> Tree N.Nat2 a; setHead x (Node (Node _ u) v) = Node (Node (Leaf x) u) v
Then without a spine, it will fail:
>>>
leftmost $ setHead 'x' v
*** Exception: err ...
But with the spine, it won't:
>>>
leftmost $ setHead 'x' $ ensureSpine v
'x'