Copyright | (c) gspia 2020- |
---|---|
License | BSD |
Maintainer | gspia |
Safe Haskell | Safe |
Language | Haskell2010 |
Synopsis
- data TreeF a b = NodeF a [b]
- data TreeToFix :: Tree a -> Exp (Fix (TreeF a))
- data SumNodesAlg :: Algebra (TreeF Nat) Nat
- data CountNodesAlg :: Algebra (TreeF a) Nat
- data Size :: Tree a -> Exp Nat
- data BuildNodeCoA :: CoAlgebra (TreeF Nat) Nat
- data BuildFibTreeCoA :: CoAlgebra (TreeF Nat) Nat
- data Fib :: Nat -> Exp Nat
- data BTreeF a b
Documentation
NodeF a [b] |
Instances
type Eval (TreeToFix (Node a2 (b ': bs)) :: Fix (TreeF a1) -> Type) Source # | |
type Eval (TreeToFix (Node a2 ([] :: [Tree a1])) :: Fix (TreeF a1) -> Type) Source # | |
type Eval (BuildFibTreeCoA n :: TreeF Nat Nat -> Type) Source # | |
type Eval (BuildNodeCoA n :: TreeF Nat Nat -> Type) Source # | |
type Eval (Map f (NodeF a3 (b2 ': bs)) :: TreeF a2 b1 -> Type) Source # | |
type Eval (Map f (NodeF a3 ([] :: [a1])) :: TreeF a2 b -> Type) Source # | |
data TreeToFix :: Tree a -> Exp (Fix (TreeF a)) Source #
A function to transform a Tree into fixed structure that can be used by Cata and Ana.
See the implementation of Size
for an example.
data SumNodesAlg :: Algebra (TreeF Nat) Nat Source #
Sum the nodes of TreeF containing Nats.
See the implementation of Fib
for an example.
Instances
type Eval (SumNodesAlg (NodeF x (b ': bs)) :: Nat -> Type) Source # | |
Defined in Fcf.Alg.Tree | |
type Eval (SumNodesAlg (NodeF x ([] :: [Nat])) :: Nat -> Type) Source # | |
Defined in Fcf.Alg.Tree |
data CountNodesAlg :: Algebra (TreeF a) Nat Source #
Count the nodes of TreeF.
See the Size
for an example.
Instances
type Eval (CountNodesAlg (NodeF x (b ': bs)) :: Nat -> Type) Source # | |
Defined in Fcf.Alg.Tree | |
type Eval (CountNodesAlg (NodeF x ([] :: [Nat])) :: Nat -> Type) Source # | |
Defined in Fcf.Alg.Tree |
data Size :: Tree a -> Exp Nat Source #
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) :: Nat = 7
data BuildNodeCoA :: CoAlgebra (TreeF Nat) Nat Source #
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)
data Fib :: Nat -> Exp Nat Source #
Fibonaccis with Hylo, not efficient
Example
>>>
:kind! Eval (Fib 10)
Eval (Fib 10) :: Nat = 55
BTreeF is a btree functor. At the moment, it is used to build sorting algorithms.
Instances
type Eval (PartHlp smaller (h ': t) :: BTreeF a [a] -> Type) Source # | |
type Eval (PartHlp _ ([] :: [a]) :: BTreeF a [a] -> Type) Source # | |
type Eval (PartCmp cmp coalg :: BTreeF a [a] -> Type) Source # | |
type Eval (Map f (BNodeF a4 b1 b2) :: BTreeF a3 a2 -> Type) Source # | |
type Eval (Map f (BEmptyF :: BTreeF a2 a1) :: BTreeF a2 b -> Type) Source # | |