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
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, Tree a -> Tree a -> Bool
Tree a -> Tree a -> Ordering
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
Ord)

treeF :: Tree (a, F b c) -> F (Path, b) (a, c)
treeF :: forall a b c. Tree (a, F b c) -> F (Path, b) (a, c)
treeF = forall hi ho. FSP hi ho -> F hi ho
F{-ff-} forall b c a. (b -> c) -> (a -> 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' :: forall a b c. Tree (a, F b c) -> FSP (Path, b) (a, c)
treeF' (Leaf (a
t, F b c
f)) = forall {a} {b} {c} {a}.
a -> F b c -> Fa TEvent TCommand ([a], b) (a, c)
leafF a
t F b c
f
treeF' (Branch Tree (a, F b c)
l Tree (a, F b c)
r) = forall a b. FSP (Path, a) b -> FSP (Path, a) b -> FSP (Path, a) b
branchFSP (forall a b c. Tree (a, F b c) -> FSP (Path, b) (a, c)
treeF' Tree (a, F b c)
l) (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 c -> Fa TEvent TCommand ([a], b) (a, c)
leafF a
t (F FSP b c
sp) =
    let pre :: ([a], b) -> b
pre ([], b
x) = b
x
        pre ([a], b)
_ = forall a. HasCallStack => [Char] -> a
error [Char]
"unknown path in treeF"
    in  forall a b c d e f.
(a -> b) -> (c -> d) -> Fa e f b c -> Fa e f a d
prepostMapHigh' forall {a} {b}. ([a], b) -> b
pre (forall {a} {b}. a -> b -> (a, b)
pair a
t) FSP b c
sp