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.DF

Depth indexed perfect tree as data family.

  • 35 values
  • Packageral-0.2.2
  • Exports38
  • LanguageHaskell2010
  • LicenceGPL-2.0-or-later
  • SourceDF.hs
data familydata family Tree (n :: Nat) a
#
Instances26Functor, Applicative, Foldable, Traversable, Foldable1, Arbitrary1, …

Construction

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

Tree with exactly one element.

Example1 expression
singleton TrueLeaf True

Conversions

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

Convert Tree to list.

Example1 expression
toList $ Node (Node (Leaf 'f') (Leaf 'o')) (Node (Leaf 'o') (Leaf 'd'))"food"
valuereverse :: SNatI n => 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(!) :: SNatI n => Tree n a -> Wrd n -> a
#

Indexing.

Example2 expressions
let t = Node (Node (Leaf 'a') (Leaf 'b')) (Node (Leaf 'c') (Leaf 'd'))t ! W1 (W0 WE)'c'
valuetabulate :: SNatI n => (Wrd n -> a) -> Tree n a
#

Tabulating, inverse of !.

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

Folds

10 declarations
valuefoldr :: SNatI n => (a -> b -> b) -> b -> Tree n a -> b
#

Right fold.

valueifoldr :: SNatI n => (Wrd n -> a -> b -> b) -> b -> Tree n a -> b
#

Right fold with an index.

valuefoldl :: SNatI n => (b -> a -> b) -> b -> Tree n a -> b
#

Left fold.

valueifoldl :: SNatI n => (Wrd n -> b -> a -> b) -> b -> Tree n a -> b
#

Left fold with an index.

Special folds

4 declarations

Mapping

7 declarations
valuemap :: SNatI n => (a -> b) -> Tree n a -> Tree n b
#
Example1 expression
map not $ Node (Leaf True) (Leaf False)Node (Leaf False) (Leaf True)
valueimap :: SNatI n => (Wrd n -> a -> b) -> Tree n a -> Tree n b
#
Example2 expressions
let t = Node (Node (Leaf 'a') (Leaf 'b')) (Node (Leaf 'c') (Leaf 'd'))imap (,) tNode (Node (Leaf (0b00,'a')) (Leaf (0b01,'b'))) (Node (Leaf (0b10,'c')) (Leaf (0b11,'d')))

Zipping

3 declarations
valuerepeat :: SNatI n => x -> Tree n x
#

Repeat 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 Wrd n in a 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

Ensure spine

1 declaration
valueensureSpine :: SNatI n => Tree n a -> Tree n a
#

Ensure spine.

If we have an undefined Tree,

Example1 expression
let v = error "err" :: Tree N.Nat2 Char

And insert data into it later:

Example1 expression
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:

Example1 expression
leftmost $ setHead 'x' v*** Exception: err...

But with the spine, it won't:

Example1 expression
leftmost $ setHead 'x' $ ensureSpine v'x'