{-# LANGUAGE TypeOperators #-} module TreeExample where import TreeRep import Generics.MultiRec.Elems.Many import Generics.MultiRec.GMap import Generics.MultiRec.Eq import Generics.MultiRec.FoldAlgK import qualified Generics.MultiRec.Show as GS import qualified Generics.MultiRec.ZipWith as Z import Data.Char example :: Tree Int String example = Branch (Leaf 101) "test" (Branch (Leaf 114) "multirec" (Leaf 105)) example2 :: Tree Int String example2 = Branch (Branch (Leaf 3) "def" (Leaf 2)) "abc" (Leaf 1) example3 :: Tree Int String example3 = Branch (Leaf 102) "tast" (Branch (Leaf 113) "multirac" (Leaf 106)) gmapExample :: Tree Char Int gmapExample = gmap (apply $ chr & length) Tree Tree example eqTest1 = eq Tree example example eqTest2 = eq Tree example example3 treeAlg :: Algebra TreeU (Int :|: String :|: Nil) Int treeAlg _ = (\e -> e) & (\n e o -> n + length e + o) foldExample = fold treeAlg Tree example showExample = putStrLn . GS.show Tree $ example -- This produces an infinite loop in the type checker. TODO: create -- minimal example and report. It shouldn't type check, but it -- shouldn't hang the compiler either. From a type checker trace, it -- seems it tries to create an infinite ZRes type. -- zipExample = Z.zipWith (ezip . apply $ (+) & (++)) Tree Tree Tree example example3 zipExample = Z.zipWith (ezip . apply ((+) & (++))) Tree Tree Tree example example3