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 FibHylo :: Nat -> Exp Nat
- data BTreeF a b
- data FSum :: f a -> Exp a
- data Sizes :: Fix f -> Exp (Ann f Nat)
- data NatF r
- data NatToFix :: Nat -> Exp (Fix NatF)
- data RecNTF :: Nat -> Exp (Fix NatF)
- data FibAlgebra :: NatF (Ann NatF Nat) -> Exp Nat
- data FibHisto :: Nat -> Exp Nat
Documentation
NodeF a [b] |
Instances
type Eval (FSum (NodeF a2 (b ': bs)) :: Nat -> Type) Source # | |
type Eval (FSum (NodeF a2 ([] :: [Nat])) :: Nat -> Type) Source # | Instances to make TreeF to be a foldable sum. After this one, we can write
the |
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 FibHylo :: Nat -> Exp Nat Source #
Fibonaccis with Hylo, not efficient
Example
>>>
:kind! Eval (FibHylo 10)
Eval (FibHylo 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 # | BTreeF is a functor |
data FSum :: f a -> Exp a Source #
A kind of foldable sum class. Pun may or may not be intended.
data Sizes :: Fix f -> Exp (Ann f Nat) Source #
Instances
type Eval (Sizes fx :: Ann f Nat -> Type) Source # | Sizes example from Recursion Schemes by example, Tim Williams. This annotes each node with the size of its subtree. Example
|
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.
Instances
type Eval (FibAlgebra (Succ (Fix (AnnF ((,) (Succ (Fix (AnnF ((,) _ n)))) m)))) :: Nat -> Type) Source # | |
type Eval (FibAlgebra (Succ (Fix (AnnF ((,) (Zero :: NatF (Fix (AnnF NatF Nat))) _)))) :: Nat -> Type) Source # | |
type Eval (FibAlgebra (Zero :: NatF (Ann NatF Nat))) Source # | |
Defined in Fcf.Alg.Tree | |
type Eval (RecNTF n :: Fix NatF -> Type) Source # | |
type Eval (NatToFix n :: Fix NatF -> Type) Source # | |
type Eval (Map f (Succ r2) :: NatF r1 -> Type) Source # | |
type Eval (Map f (Zero :: NatF a) :: NatF b -> Type) Source # | NatF has to have functor-instances so that morphisms will work. |
data NatToFix :: Nat -> Exp (Fix NatF) Source #
We want to be able to build NatF Fix-structures out of Nat's.
data FibAlgebra :: NatF (Ann NatF Nat) -> Exp Nat Source #
Efficient Fibonacci algebra from Recursion Schemes by example, Tim Williams.
Instances
type Eval (FibAlgebra (Succ (Fix (AnnF ((,) (Succ (Fix (AnnF ((,) _ n)))) m)))) :: Nat -> Type) Source # | |
type Eval (FibAlgebra (Succ (Fix (AnnF ((,) (Zero :: NatF (Fix (AnnF NatF Nat))) _)))) :: Nat -> Type) Source # | |
type Eval (FibAlgebra (Zero :: NatF (Ann NatF Nat))) Source # | |
Defined in Fcf.Alg.Tree |