HORIZON HASKELLDocslts/ghc-9.14.x99ffbb82026-10-19Search packagesCtrl K
Theme: |

GHC 9.14.1 · lts/ghc-9.14.x · 99ffbb8 · 2026-10-19

Moduleral-0.2.2Haskell2010

Data.RAVec.Tree

Depth indexed perfect binary tree.

Contents
  1. Construction
  2. Conversions
  3. Indexing
  4. Folds
  5. Special folds
  6. Mapping
  7. Zipping
  8. Universe
  9. QuickCheck
Synopsis
  • 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

valuesingleton :: a -> Tree 'Z a

Tree of zero depth, with single element.

Example1 expression
singleton TrueLeaf True

Conversions

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

Folds

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

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

Mapping

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

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

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