HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulefcf-containers-0.8.2Haskell2010

Fcf.Alg.Tree

Fcf.Alg.Tree

Type-level TreeF and BTreeF to be used with Cata, Ana and Hylo. This also provides some algorithms: general purpose sorting with Qsort, Size of an Tree, Fibonaccis.

  • 16 types
datadata TreeF a b
#

TreeF is functor for Trees. TreeF has Map-instance (on structure).

Constructors

Instances8Eval, …
datadata Size (b :: Tree a) (c :: Nat)
#

Size of the Tree is the number of nodes in it.

Example

Size is defined as Cata CountNodesAlg =<< TreeToFix tr and can be used with the following.

data BuildNode :: Nat -> Exp (Nat,[Nat])
:{

type instance Eval (BuildNode x) = If (Eval ((2 TL.* x TL.+ 1) >= 8)) '(x, '[]) '(x, '[ 2 TL.* x, (2 TL.* x) TL.+ 1 ]) :}

:kind! Eval (Size =<< UnfoldTree BuildNode 1)

Eval (Size =<< UnfoldTree BuildNode 1) :: TL.Natural = 7

Instances1Eval
datadata BuildNodeCoA (a :: Nat) (b :: TreeF Nat Nat)
#

CoAlgebra to build TreeF's. This is an example from containers-package. See Size and example in there.

:kind! Eval (Ana BuildNodeCoA 1) :kind! Eval (Hylo CountNodesAlg BuildNodeCoA 1)

Instances1Eval
datadata BTreeF a b
#

BTreeF is a btree functor. At the moment, it is used to build sorting algorithms.

Constructors

Instances5Eval
datadata FSum (b :: f a) (c :: a)
#

A kind of foldable sum class. Pun may or may not be intended.

Instances2Eval
  • type Eval (FSum ('NodeF a2 '[])) = 0Defined in fcf-containers-0.8.2 · Fcf.Alg.Tree

    Instances to make TreeF to be a foldable sum. After this one, we can write the Sizes example.

  • type Eval (FSum ('NodeF a2 (b ': bs))) = Eval (Sum (b ': bs))Defined in fcf-containers-0.8.2 · Fcf.Alg.Tree
datadata Sizes (a :: Fix f) (b :: Ann f Nat)
#
Instances1Eval
  • type Eval (Sizes fx) = Eval (Synthesize ((+) 1 <=< FSum) fx)Defined in fcf-containers-0.8.2 · Fcf.Alg.Tree

    Sizes example from Recursion Schemes by example, Tim Williams. This annotes each node with the size of its subtree.

    Example

    :kind! Eval (Sizes =<< Ana BuildNodeCoA 1)

    Eval (Sizes =<< Ana BuildNodeCoA 1) :: Fix (AnnF (TreeF TL.Natural) TL.Natural) = 'Fix ('AnnF '( 'NodeF 1 '[ 'Fix ('AnnF '( 'NodeF 2 '[ 'Fix ('AnnF '( 'NodeF 4 '[], 1)), 'Fix ('AnnF '( 'NodeF 5 '[], 1))], 3)), 'Fix ('AnnF '( 'NodeF 3 '[ 'Fix ('AnnF '( 'NodeF 6 '[], 1)), 'Fix ('AnnF '( 'NodeF 7 '[], 1))], 3))], 7))

datadata NatF r
#

A NatF functor that can be used with different morphisms. This tree-module is probably a wrong place to this one. Now it is here for the Fibonacci example.

Constructors

Instances7Eval, …
datadata FibHisto (a :: Nat) (b :: Nat)
#

Efficient Fibonacci type-level function (from Recursion Schemes by example, Tim Williams). Compare this to FibHylo.

Example

:kind! Eval (FibHisto 100)

Eval (FibHisto 100) :: TL.Natural = 354224848179261915075

Instances1Eval