HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

Moduleral-0.2.2Haskell2010

Data.RAVec.Tree

Depth indexed perfect binary tree.

  • 1 type
  • 34 values
  • Packageral-0.2.2
  • Exports35
  • LanguageHaskell2010
  • LicenceGPL-2.0-or-later
  • SourceTree.hs
datadata Tree (n :: Nat) a where
#

Perfectly balanced binary tree of depth n, with 2 ^ n elements.

Constructors

Instances23Functor, Applicative, Foldable, Traversable, Foldable1, Arbitrary1, …

Construction

1 declaration
valuesingleton :: a -> Tree 'Z a
#

Tree of zero depth, with single element.

Example1 expression
singleton TrueLeaf True

Conversions

2 declarations
valuetoList :: Tree n a -> [a]
#

Convert Tree to list.

Example1 expression
toList $ Node (Node (Leaf 'a') (Leaf 'b')) (Node (Leaf 'c') (Leaf 'd'))"abcd"
valuereverse :: Tree n a -> Tree n a
#

Reverse Tree.

Example2 expressions
let t = Node (Node (Leaf 'a') (Leaf 'b')) (Node (Leaf 'c') (Leaf 'd'))reverse tNode (Node (Leaf 'd') (Leaf 'c')) (Node (Leaf 'b') (Leaf 'a'))

Indexing

4 declarations
value(!) :: Tree n a -> Wrd n -> a
#

Indexing.

Folds

10 declarations
valuefoldr :: (a -> b -> b) -> b -> Tree n a -> b
#
Example1 expression
foldr (:) [] $ Node (Leaf True) (Leaf False)[True,False]
valuefoldl :: (b -> a -> b) -> b -> Tree n a -> b
#
Example1 expression
foldl (flip (:)) [] $ Node (Leaf True) (Leaf False)[False,True]

Special folds

4 declarations
valuelength :: Tree n a -> Int
#
Example1 expression
length (universe :: Tree N.Nat3 (Wrd N.Nat3))8

Mapping

7 declarations
valuemap :: (a -> b) -> Tree n a -> Tree n b
#
Example1 expression
map not $ Node (Leaf True) (Leaf False)Node (Leaf False) (Leaf True)
valueimap :: (Wrd n -> a -> b) -> Tree n a -> Tree n b
#
Example1 expression
imap (,) $ Node (Leaf True) (Leaf False)Node (Leaf (0b0,True)) (Leaf (0b1,False))

Zipping

3 declarations
valuezipWith :: (a -> b -> c) -> Tree n a -> Tree n b -> Tree n c
#

Zip two Vecs with a function.

valueizipWith :: (Wrd n -> a -> b -> c) -> Tree n a -> Tree n b -> Tree n c
#

Zip two Trees. with a function that also takes the elements' indices.

valuerepeat :: SNatI n => a -> Tree n a
#

Repeat a value.

Example1 expression
repeat 'x' :: Tree N.Nat2 CharNode (Node (Leaf 'x') (Leaf 'x')) (Node (Leaf 'x') (Leaf 'x'))

Universe

1 declaration
valueuniverse :: SNatI n => Tree n (Wrd n)
#

Get all Vec n Bool indices in Tree n.

Example1 expression
universe :: Tree N.Nat2 (Wrd N.Nat2)Node (Node (Leaf 0b00) (Leaf 0b01)) (Node (Leaf 0b10) (Leaf 0b11))

QuickCheck

2 declarations