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

Depth indexed perfect tree as data family.

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

Conversions

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

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

Special folds

Mapping

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

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

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

Ensure spine

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'