import Mpi -- some auxiliary functions -- uncurried multiplication, mult (x,y) = x*y mult = uncurry (*) -- uncurried sum add = uncurry (+) -- uncurried max maxi = uncurry max -- isZero n = n==0 isZero = (==0) -- Arvores Binarias etiquetadas nas folhas data LTree a = Leaf a | LNode (LTree a) (LTree a) inLTree :: Either a (LTree a , LTree a) -> LTree a inLTree = either Leaf (uncurry LNode) outLTree :: LTree a -> Either a (LTree a , LTree a) outLTree (Leaf x) = i1 x outLTree (LNode e d) = i2 (e,d) alturaL = (either (const 0) (succ.maxi.(alturaL >< alturaL))) . outLTree alturaL' = (either (const 0) (succ.maxi)) . (id -|- alturaL' >< alturaL') . outLTree somaFolhas = (either id add) . (id -|- somaFolhas >< somaFolhas) . outLTree -- Arvores Binarias etiquetadas nos nos. data BTree a = Empty | BNode a (BTree a) (BTree a) inBTree :: Either () ((a, BTree a) , BTree a) -> BTree a inBTree = either (const Empty) (uncurry (uncurry BNode)) outBTree :: BTree a -> Either () ((a, BTree a), BTree a) outBTree Empty = i1 () outBTree (BNode x e d) = i2 ((x,e),d) alturaB = (either (const 0) (succ.maxi.(snd >< id))) . (id -|- (id >< alturaB) >< alturaB) . outBTree somaNodos = (either (const 0) (add.(add >< id))) . (id -|- (id >< somaNodos) >< somaNodos) . outBTree t :: LTree Integer t = LNode (Leaf 1) (LNode (Leaf 2) (Leaf 3)) t' = LNode t t a :: BTree Integer a = BNode 1 (BNode 2 Empty Empty) (BNode 3 Empty Empty) a'= BNode 0 a a