module TreeF where
import BranchF
import CompFfun(prepostMapHigh')
import Utils(pair)
import Fudget

data Tree a = Leaf a | Branch (Tree a) (Tree a)  deriving (Tree a -> Tree a -> Bool
(Tree a -> Tree a -> Bool)
-> (Tree a -> Tree a -> Bool) -> Eq (Tree a)
forall a. Eq a => Tree a -> Tree a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Tree a -> Tree a -> Bool
$c/= :: forall a. Eq a => Tree a -> Tree a -> Bool
== :: Tree a -> Tree a -> Bool
$c== :: forall a. Eq a => Tree a -> Tree a -> Bool
Eq, Eq (Tree a)
Eq (Tree a)
-> (Tree a -> Tree a -> Ordering)
-> (Tree a -> Tree a -> Bool)
-> (Tree a -> Tree a -> Bool)
-> (Tree a -> Tree a -> Bool)
-> (Tree a -> Tree a -> Bool)
-> (Tree a -> Tree a -> Tree a)
-> (Tree a -> Tree a -> Tree a)
-> Ord (Tree a)
Tree a -> Tree a -> Bool
Tree a -> Tree a -> Ordering
Tree a -> Tree a -> Tree a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (Tree a)
forall a. Ord a => Tree a -> Tree a -> Bool
forall a. Ord a => Tree a -> Tree a -> Ordering
forall a. Ord a => Tree a -> Tree a -> Tree a
min :: Tree a -> Tree a -> Tree a
$cmin :: forall a. Ord a => Tree a -> Tree a -> Tree a
max :: Tree a -> Tree a -> Tree a
$cmax :: forall a. Ord a => Tree a -> Tree a -> Tree a
>= :: Tree a -> Tree a -> Bool
$c>= :: forall a. Ord a => Tree a -> Tree a -> Bool
> :: Tree a -> Tree a -> Bool
$c> :: forall a. Ord a => Tree a -> Tree a -> Bool
<= :: Tree a -> Tree a -> Bool
$c<= :: forall a. Ord a => Tree a -> Tree a -> Bool
< :: Tree a -> Tree a -> Bool
$c< :: forall a. Ord a => Tree a -> Tree a -> Bool
compare :: Tree a -> Tree a -> Ordering
$ccompare :: forall a. Ord a => Tree a -> Tree a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (Tree a)
Ord)

treeF :: Tree (a, F b c) -> F (Path, b) (a, c)
treeF :: Tree (a, F b c) -> F (Path, b) (a, c)
treeF = FSP (Path, b) (a, c) -> F (Path, b) (a, c)
forall hi ho. FSP hi ho -> F hi ho
F{-ff-} (FSP (Path, b) (a, c) -> F (Path, b) (a, c))
-> (Tree (a, F b c) -> FSP (Path, b) (a, c))
-> Tree (a, F b c)
-> F (Path, b) (a, c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tree (a, F b c) -> FSP (Path, b) (a, c)
forall a b c. Tree (a, F b c) -> FSP (Path, b) (a, c)
treeF'

treeF' :: Tree (a, F b c) -> FSP (Path, b) (a, c)
treeF' :: Tree (a, F b c) -> FSP (Path, b) (a, c)
treeF' (Leaf (a
t, F b c
f)) = a -> F b c -> FSP (Path, b) (a, c)
forall a b b a. a -> F b b -> Fa TEvent TCommand ([a], b) (a, b)
leafF a
t F b c
f
treeF' (Branch Tree (a, F b c)
l Tree (a, F b c)
r) = FSP (Path, b) (a, c)
-> FSP (Path, b) (a, c) -> FSP (Path, b) (a, c)
forall a b. FSP (Path, a) b -> FSP (Path, a) b -> FSP (Path, a) b
branchFSP (Tree (a, F b c) -> FSP (Path, b) (a, c)
forall a b c. Tree (a, F b c) -> FSP (Path, b) (a, c)
treeF' Tree (a, F b c)
l) (Tree (a, F b c) -> FSP (Path, b) (a, c)
forall a b c. Tree (a, F b c) -> FSP (Path, b) (a, c)
treeF' Tree (a, F b c)
r)

leafF :: a -> F b b -> Fa TEvent TCommand ([a], b) (a, b)
leafF a
t (F FSP b b
sp) =
    let pre :: ([a], p) -> p
pre ([], p
x) = p
x
        pre ([a], p)
_ = [Char] -> p
forall a. HasCallStack => [Char] -> a
error [Char]
"unknown path in treeF"
    in  (([a], b) -> b)
-> (b -> (a, b)) -> FSP b b -> Fa TEvent TCommand ([a], b) (a, b)
forall a b c d e f.
(a -> b) -> (c -> d) -> Fa e f b c -> Fa e f a d
prepostMapHigh' ([a], b) -> b
forall a p. ([a], p) -> p
pre (a -> b -> (a, b)
forall a b. a -> b -> (a, b)
pair a
t) FSP b b
sp