{-# OPTIONS_GHC -Wno-name-shadowing #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Data.Traversable.TreeLike
( TreeLike(..), treeFoldMap
, Forest(..), Flat(..), List(..)
, inorder, preorder, postorder, levelorder, rlevelorder
, InOrder(..), PreOrder(..), PostOrder(..), LevelOrder(..), RLevelOrder(..)
, showTree, printTree
) where
import Data.Functor.Compose (Compose(..))
import Data.Functor.Const (Const(..))
import Data.Functor.Product (Product(..))
import Data.Functor.Sum (Sum(..))
import Data.Traversable (foldMapDefault)
import Data.Tree hiding (Forest)
import Control.Applicative.Phases
import Data.BinaryTree
import Data.Monoid.TreeDiagram
showTree :: (TreeLike tree, Show a) => tree a -> ShowS
showTree :: forall (tree :: * -> *) a.
(TreeLike tree, Show a) =>
tree a -> ShowS
showTree = TreeDiagram -> ShowS
showTreeDiagram forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m (tree :: * -> *) a.
(Monoid m, TreeLike tree) =>
(a -> m) -> (m -> m) -> tree a -> m
treeFoldMap forall a. Show a => a -> TreeDiagram
singleton TreeDiagram -> TreeDiagram
subtree
printTree :: (TreeLike tree, Show a) => tree a -> IO ()
printTree :: forall (tree :: * -> *) a.
(TreeLike tree, Show a) =>
tree a -> IO ()
printTree = String -> IO ()
putStrLn forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. (a -> b) -> a -> b
$ []) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (tree :: * -> *) a.
(TreeLike tree, Show a) =>
tree a -> ShowS
showTree
class Functor tree => TreeLike tree where
treeTraverse :: Applicative f
=> (a -> f b)
-> (forall subtree. TreeLike subtree => subtree a -> f (subtree b))
-> tree a -> f (tree b)
treeFoldMap :: (Monoid m, TreeLike tree) => (a -> m) -> (m -> m) -> tree a -> m
treeFoldMap :: forall m (tree :: * -> *) a.
(Monoid m, TreeLike tree) =>
(a -> m) -> (m -> m) -> tree a -> m
treeFoldMap a -> m
f m -> m
g = forall {k} a (b :: k). Const a b -> a
getConst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (tree :: * -> *) (f :: * -> *) a b.
(TreeLike tree, Applicative f) =>
(a -> f b)
-> (forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b))
-> tree a
-> f (tree b)
treeTraverse (forall {k} a (b :: k). a -> Const a b
Const forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m
f) (forall {k} a (b :: k). a -> Const a b
Const forall b c a. (b -> c) -> (a -> b) -> a -> c
. m -> m
g forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m (tree :: * -> *) a.
(Monoid m, TreeLike tree) =>
(a -> m) -> (m -> m) -> tree a -> m
treeFoldMap a -> m
f m -> m
g)
instance TreeLike Tree where
treeTraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> (forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b))
-> Tree a
-> f (Tree b)
treeTraverse a -> f b
f forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
g (Node a
a [Tree a]
as) = forall a. a -> [Tree a] -> Tree a
Node forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
g [Tree a]
as
instance TreeLike BinaryTree where
treeTraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> (forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b))
-> BinaryTree a
-> f (BinaryTree b)
treeTraverse a -> f b
_ forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
_ BinaryTree a
Leaf = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. BinaryTree a
Leaf
treeTraverse a -> f b
f forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
g (Branch BinaryTree a
l a
a BinaryTree a
r) = forall a. BinaryTree a -> a -> BinaryTree a -> BinaryTree a
Branch forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
g BinaryTree a
l forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> f b
f a
a forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
g BinaryTree a
r
instance (TreeLike fst, TreeLike snd) => TreeLike (Product fst snd) where
treeTraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> (forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b))
-> Product fst snd a
-> f (Product fst snd b)
treeTraverse a -> f b
_ forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
g (Pair fst a
x snd a
y) = forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
g fst a
x forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
g snd a
y
instance (TreeLike left, TreeLike right) => TreeLike (Sum left right) where
treeTraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> (forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b))
-> Sum left right a
-> f (Sum left right b)
treeTraverse a -> f b
_ forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
g (InL left a
x) = forall {k} (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
g left a
x
treeTraverse a -> f b
_ forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
g (InR right a
y) = forall {k} (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
InR forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
g right a
y
newtype Forest t tree a = Forest { forall (t :: * -> *) (tree :: * -> *) a.
Forest t tree a -> t (tree a)
getForest :: t (tree a) }
deriving forall a b. a -> Forest t tree b -> Forest t tree a
forall a b. (a -> b) -> Forest t tree a -> Forest t tree b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
forall (t :: * -> *) (tree :: * -> *) a b.
(Functor t, Functor tree) =>
a -> Forest t tree b -> Forest t tree a
forall (t :: * -> *) (tree :: * -> *) a b.
(Functor t, Functor tree) =>
(a -> b) -> Forest t tree a -> Forest t tree b
<$ :: forall a b. a -> Forest t tree b -> Forest t tree a
$c<$ :: forall (t :: * -> *) (tree :: * -> *) a b.
(Functor t, Functor tree) =>
a -> Forest t tree b -> Forest t tree a
fmap :: forall a b. (a -> b) -> Forest t tree a -> Forest t tree b
$cfmap :: forall (t :: * -> *) (tree :: * -> *) a b.
(Functor t, Functor tree) =>
(a -> b) -> Forest t tree a -> Forest t tree b
Functor
instance (Traversable t, TreeLike tree) => TreeLike (Forest t tree) where
treeTraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> (forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b))
-> Forest t tree a
-> f (Forest t tree b)
treeTraverse a -> f b
_ forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
g = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (t :: * -> *) (tree :: * -> *) a.
t (tree a) -> Forest t tree a
Forest forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
g forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (tree :: * -> *) a.
Forest t tree a -> t (tree a)
getForest
newtype List a = List { forall a. List a -> [a]
getList :: [a] }
deriving forall a b. a -> List b -> List a
forall a b. (a -> b) -> List a -> List b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> List b -> List a
$c<$ :: forall a b. a -> List b -> List a
fmap :: forall a b. (a -> b) -> List a -> List b
$cfmap :: forall a b. (a -> b) -> List a -> List b
Functor
instance TreeLike List where
treeTraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> (forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b))
-> List a
-> f (List b)
treeTraverse a -> f b
f forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
g (List [a]
as) = forall a. [a] -> List a
List forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> case [a]
as of
[] -> forall (f :: * -> *) a. Applicative f => a -> f a
pure []
a
a:[a]
as -> (:) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. List a -> [a]
getList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
g forall b c a. (b -> c) -> (a -> b) -> a -> c
.forall a. [a] -> List a
List) [a]
as
newtype Flat t a = Flat { forall (t :: * -> *) a. Flat t a -> t a
getFlat :: t a }
deriving forall a b. a -> Flat t b -> Flat t a
forall a b. (a -> b) -> Flat t a -> Flat t b
forall (t :: * -> *) a b. Functor t => a -> Flat t b -> Flat t a
forall (t :: * -> *) a b.
Functor t =>
(a -> b) -> Flat t a -> Flat t b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Flat t b -> Flat t a
$c<$ :: forall (t :: * -> *) a b. Functor t => a -> Flat t b -> Flat t a
fmap :: forall a b. (a -> b) -> Flat t a -> Flat t b
$cfmap :: forall (t :: * -> *) a b.
Functor t =>
(a -> b) -> Flat t a -> Flat t b
Functor
instance Traversable t => TreeLike (Flat t) where
treeTraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> (forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b))
-> Flat t a
-> f (Flat t b)
treeTraverse a -> f b
f forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
_ (Flat t a
ta) = forall (t :: * -> *) a. t a -> Flat t a
Flat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> f b
f t a
ta
instance (TreeLike outer, TreeLike inner) => TreeLike (Compose outer inner) where
treeTraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> (forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b))
-> Compose outer inner a
-> f (Compose outer inner b)
treeTraverse a -> f b
_ forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
g (Compose outer (inner a)
trees) = forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (tree :: * -> *) (f :: * -> *) a b.
(TreeLike tree, Applicative f) =>
(a -> f b)
-> (forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b))
-> tree a
-> f (tree b)
treeTraverse forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
g (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b)
g forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose) outer (inner a)
trees
inorder :: (Applicative f, TreeLike tree) => (a -> f b) -> tree a -> f (tree b)
inorder :: forall (f :: * -> *) (tree :: * -> *) a b.
(Applicative f, TreeLike tree) =>
(a -> f b) -> tree a -> f (tree b)
inorder a -> f b
f = forall (tree :: * -> *) (f :: * -> *) a b.
(TreeLike tree, Applicative f) =>
(a -> f b)
-> (forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b))
-> tree a
-> f (tree b)
treeTraverse a -> f b
f (forall (f :: * -> *) (tree :: * -> *) a b.
(Applicative f, TreeLike tree) =>
(a -> f b) -> tree a -> f (tree b)
inorder a -> f b
f)
preorder :: (Applicative f, TreeLike tree) => (a -> f b) -> tree a -> f (tree b)
preorder :: forall (f :: * -> *) (tree :: * -> *) a b.
(Applicative f, TreeLike tree) =>
(a -> f b) -> tree a -> f (tree b)
preorder a -> f b
f = forall (f :: * -> *) a. Applicative f => Phases f a -> f a
runPhasesForwards forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (tree :: * -> *) (f :: * -> *) a b.
(TreeLike tree, Applicative f) =>
(a -> f b)
-> (forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b))
-> tree a
-> f (tree b)
treeTraverse (forall (f :: * -> *) a. f a -> Phases f a
now forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f b
f) (forall (f :: * -> *) a. Applicative f => f a -> Phases f a
later forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) (tree :: * -> *) a b.
(Applicative f, TreeLike tree) =>
(a -> f b) -> tree a -> f (tree b)
preorder a -> f b
f)
postorder :: (Applicative f, TreeLike tree) => (a -> f b) -> tree a -> f (tree b)
postorder :: forall (f :: * -> *) (tree :: * -> *) a b.
(Applicative f, TreeLike tree) =>
(a -> f b) -> tree a -> f (tree b)
postorder a -> f b
f = forall (f :: * -> *) a. Applicative f => Phases f a -> f a
runPhasesBackwards forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (tree :: * -> *) (f :: * -> *) a b.
(TreeLike tree, Applicative f) =>
(a -> f b)
-> (forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b))
-> tree a
-> f (tree b)
treeTraverse (forall (f :: * -> *) a. f a -> Phases f a
now forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f b
f) (forall (f :: * -> *) a. Applicative f => f a -> Phases f a
later forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) (tree :: * -> *) a b.
(Applicative f, TreeLike tree) =>
(a -> f b) -> tree a -> f (tree b)
postorder a -> f b
f)
levelorder :: (Applicative f, TreeLike tree) => (a -> f b) -> tree a -> f (tree b)
levelorder :: forall (f :: * -> *) (tree :: * -> *) a b.
(Applicative f, TreeLike tree) =>
(a -> f b) -> tree a -> f (tree b)
levelorder = \a -> f b
f -> forall (f :: * -> *) a. Applicative f => Phases f a -> f a
runPhasesForwards forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) (tree :: * -> *) a b.
(Applicative f, TreeLike tree) =>
(a -> f b) -> tree a -> Phases f (tree b)
schedule a -> f b
f where
schedule :: (Applicative f, TreeLike tree) => (a -> f b) -> tree a -> Phases f (tree b)
schedule :: forall (f :: * -> *) (tree :: * -> *) a b.
(Applicative f, TreeLike tree) =>
(a -> f b) -> tree a -> Phases f (tree b)
schedule a -> f b
f = forall (tree :: * -> *) (f :: * -> *) a b.
(TreeLike tree, Applicative f) =>
(a -> f b)
-> (forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b))
-> tree a
-> f (tree b)
treeTraverse (forall (f :: * -> *) a. f a -> Phases f a
now forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f b
f) (forall (f :: * -> *) a. Applicative f => Phases f a -> Phases f a
delay forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) (tree :: * -> *) a b.
(Applicative f, TreeLike tree) =>
(a -> f b) -> tree a -> Phases f (tree b)
schedule a -> f b
f)
rlevelorder :: (Applicative f, TreeLike tree) => (a -> f b) -> tree a -> f (tree b)
rlevelorder :: forall (f :: * -> *) (tree :: * -> *) a b.
(Applicative f, TreeLike tree) =>
(a -> f b) -> tree a -> f (tree b)
rlevelorder = \a -> f b
f -> forall (f :: * -> *) a. Applicative f => Phases f a -> f a
runPhasesBackwards forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) (tree :: * -> *) a b.
(Applicative f, TreeLike tree) =>
(a -> f b) -> tree a -> Phases f (tree b)
schedule a -> f b
f where
schedule :: (Applicative f, TreeLike tree) => (a -> f b) -> tree a -> Phases f (tree b)
schedule :: forall (f :: * -> *) (tree :: * -> *) a b.
(Applicative f, TreeLike tree) =>
(a -> f b) -> tree a -> Phases f (tree b)
schedule a -> f b
f = forall (tree :: * -> *) (f :: * -> *) a b.
(TreeLike tree, Applicative f) =>
(a -> f b)
-> (forall (subtree :: * -> *).
TreeLike subtree =>
subtree a -> f (subtree b))
-> tree a
-> f (tree b)
treeTraverse (forall (f :: * -> *) a. f a -> Phases f a
now forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f b
f) (forall (f :: * -> *) a. Applicative f => Phases f a -> Phases f a
delay forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) (tree :: * -> *) a b.
(Applicative f, TreeLike tree) =>
(a -> f b) -> tree a -> Phases f (tree b)
schedule a -> f b
f)
newtype InOrder tree a = InOrder { forall (tree :: * -> *) a. InOrder tree a -> tree a
getInOrder :: tree a }
deriving forall a b. a -> InOrder tree b -> InOrder tree a
forall a b. (a -> b) -> InOrder tree a -> InOrder tree b
forall (tree :: * -> *) a b.
Functor tree =>
a -> InOrder tree b -> InOrder tree a
forall (tree :: * -> *) a b.
Functor tree =>
(a -> b) -> InOrder tree a -> InOrder tree b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> InOrder tree b -> InOrder tree a
$c<$ :: forall (tree :: * -> *) a b.
Functor tree =>
a -> InOrder tree b -> InOrder tree a
fmap :: forall a b. (a -> b) -> InOrder tree a -> InOrder tree b
$cfmap :: forall (tree :: * -> *) a b.
Functor tree =>
(a -> b) -> InOrder tree a -> InOrder tree b
Functor
instance TreeLike tree => Foldable (InOrder tree) where
foldMap :: forall m a. Monoid m => (a -> m) -> InOrder tree a -> m
foldMap = forall (t :: * -> *) m a.
(Traversable t, Monoid m) =>
(a -> m) -> t a -> m
foldMapDefault
instance TreeLike tree => Traversable (InOrder tree) where
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> InOrder tree a -> f (InOrder tree b)
traverse a -> f b
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (tree :: * -> *) a. tree a -> InOrder tree a
InOrder forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) (tree :: * -> *) a b.
(Applicative f, TreeLike tree) =>
(a -> f b) -> tree a -> f (tree b)
inorder a -> f b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (tree :: * -> *) a. InOrder tree a -> tree a
getInOrder
newtype PreOrder tree a = PreOrder { forall (tree :: * -> *) a. PreOrder tree a -> tree a
getPreOrder :: tree a }
deriving forall a b. a -> PreOrder tree b -> PreOrder tree a
forall a b. (a -> b) -> PreOrder tree a -> PreOrder tree b
forall (tree :: * -> *) a b.
Functor tree =>
a -> PreOrder tree b -> PreOrder tree a
forall (tree :: * -> *) a b.
Functor tree =>
(a -> b) -> PreOrder tree a -> PreOrder tree b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> PreOrder tree b -> PreOrder tree a
$c<$ :: forall (tree :: * -> *) a b.
Functor tree =>
a -> PreOrder tree b -> PreOrder tree a
fmap :: forall a b. (a -> b) -> PreOrder tree a -> PreOrder tree b
$cfmap :: forall (tree :: * -> *) a b.
Functor tree =>
(a -> b) -> PreOrder tree a -> PreOrder tree b
Functor
instance TreeLike tree => Foldable (PreOrder tree) where
foldMap :: forall m a. Monoid m => (a -> m) -> PreOrder tree a -> m
foldMap = forall (t :: * -> *) m a.
(Traversable t, Monoid m) =>
(a -> m) -> t a -> m
foldMapDefault
instance TreeLike tree => Traversable (PreOrder tree) where
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PreOrder tree a -> f (PreOrder tree b)
traverse a -> f b
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (tree :: * -> *) a. tree a -> PreOrder tree a
PreOrder forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) (tree :: * -> *) a b.
(Applicative f, TreeLike tree) =>
(a -> f b) -> tree a -> f (tree b)
preorder a -> f b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (tree :: * -> *) a. PreOrder tree a -> tree a
getPreOrder
newtype PostOrder tree a = PostOrder { forall (tree :: * -> *) a. PostOrder tree a -> tree a
getPostOrder :: tree a }
deriving forall a b. a -> PostOrder tree b -> PostOrder tree a
forall a b. (a -> b) -> PostOrder tree a -> PostOrder tree b
forall (tree :: * -> *) a b.
Functor tree =>
a -> PostOrder tree b -> PostOrder tree a
forall (tree :: * -> *) a b.
Functor tree =>
(a -> b) -> PostOrder tree a -> PostOrder tree b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> PostOrder tree b -> PostOrder tree a
$c<$ :: forall (tree :: * -> *) a b.
Functor tree =>
a -> PostOrder tree b -> PostOrder tree a
fmap :: forall a b. (a -> b) -> PostOrder tree a -> PostOrder tree b
$cfmap :: forall (tree :: * -> *) a b.
Functor tree =>
(a -> b) -> PostOrder tree a -> PostOrder tree b
Functor
instance TreeLike tree => Foldable (PostOrder tree) where
foldMap :: forall m a. Monoid m => (a -> m) -> PostOrder tree a -> m
foldMap = forall (t :: * -> *) m a.
(Traversable t, Monoid m) =>
(a -> m) -> t a -> m
foldMapDefault
instance TreeLike tree => Traversable (PostOrder tree) where
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PostOrder tree a -> f (PostOrder tree b)
traverse a -> f b
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (tree :: * -> *) a. tree a -> PostOrder tree a
PostOrder forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) (tree :: * -> *) a b.
(Applicative f, TreeLike tree) =>
(a -> f b) -> tree a -> f (tree b)
postorder a -> f b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (tree :: * -> *) a. PostOrder tree a -> tree a
getPostOrder
newtype LevelOrder tree a = LevelOrder { forall (tree :: * -> *) a. LevelOrder tree a -> tree a
getLevelOrder :: tree a }
deriving forall a b. a -> LevelOrder tree b -> LevelOrder tree a
forall a b. (a -> b) -> LevelOrder tree a -> LevelOrder tree b
forall (tree :: * -> *) a b.
Functor tree =>
a -> LevelOrder tree b -> LevelOrder tree a
forall (tree :: * -> *) a b.
Functor tree =>
(a -> b) -> LevelOrder tree a -> LevelOrder tree b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> LevelOrder tree b -> LevelOrder tree a
$c<$ :: forall (tree :: * -> *) a b.
Functor tree =>
a -> LevelOrder tree b -> LevelOrder tree a
fmap :: forall a b. (a -> b) -> LevelOrder tree a -> LevelOrder tree b
$cfmap :: forall (tree :: * -> *) a b.
Functor tree =>
(a -> b) -> LevelOrder tree a -> LevelOrder tree b
Functor
instance TreeLike tree => Foldable (LevelOrder tree) where
foldMap :: forall m a. Monoid m => (a -> m) -> LevelOrder tree a -> m
foldMap = forall (t :: * -> *) m a.
(Traversable t, Monoid m) =>
(a -> m) -> t a -> m
foldMapDefault
instance TreeLike tree => Traversable (LevelOrder tree) where
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> LevelOrder tree a -> f (LevelOrder tree b)
traverse a -> f b
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (tree :: * -> *) a. tree a -> LevelOrder tree a
LevelOrder forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) (tree :: * -> *) a b.
(Applicative f, TreeLike tree) =>
(a -> f b) -> tree a -> f (tree b)
levelorder a -> f b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (tree :: * -> *) a. LevelOrder tree a -> tree a
getLevelOrder
newtype RLevelOrder tree a = RLevelOrder { forall (tree :: * -> *) a. RLevelOrder tree a -> tree a
getRLevelOrder :: tree a }
deriving forall a b. a -> RLevelOrder tree b -> RLevelOrder tree a
forall a b. (a -> b) -> RLevelOrder tree a -> RLevelOrder tree b
forall (tree :: * -> *) a b.
Functor tree =>
a -> RLevelOrder tree b -> RLevelOrder tree a
forall (tree :: * -> *) a b.
Functor tree =>
(a -> b) -> RLevelOrder tree a -> RLevelOrder tree b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> RLevelOrder tree b -> RLevelOrder tree a
$c<$ :: forall (tree :: * -> *) a b.
Functor tree =>
a -> RLevelOrder tree b -> RLevelOrder tree a
fmap :: forall a b. (a -> b) -> RLevelOrder tree a -> RLevelOrder tree b
$cfmap :: forall (tree :: * -> *) a b.
Functor tree =>
(a -> b) -> RLevelOrder tree a -> RLevelOrder tree b
Functor
instance TreeLike tree => Foldable (RLevelOrder tree) where
foldMap :: forall m a. Monoid m => (a -> m) -> RLevelOrder tree a -> m
foldMap = forall (t :: * -> *) m a.
(Traversable t, Monoid m) =>
(a -> m) -> t a -> m
foldMapDefault
instance TreeLike tree => Traversable (RLevelOrder tree) where
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> RLevelOrder tree a -> f (RLevelOrder tree b)
traverse a -> f b
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (tree :: * -> *) a. tree a -> RLevelOrder tree a
RLevelOrder forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) (tree :: * -> *) a b.
(Applicative f, TreeLike tree) =>
(a -> f b) -> tree a -> f (tree b)
rlevelorder a -> f b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (tree :: * -> *) a. RLevelOrder tree a -> tree a
getRLevelOrder