{- |
Description: Symmetric binary trees
Copyright: Copyright (C) 2021 Yoo Chung
License: GPL-3.0-or-later
Maintainer: dev@chungyc.org

Some solutions to "Problems.P56" of Ninety-Nine Haskell "Problems".
-}
module Solutions.P56 (symmetric) where

import           Problems.BinaryTrees

-- | Check whether a given binary tree is symmetric.
symmetric :: Tree a -> Bool
symmetric :: forall a. Tree a -> Bool
symmetric Tree a
Empty                 = Bool
True
symmetric (Branch a
_ Tree a
left Tree a
right) = Tree a -> Tree a -> Bool
forall a b. Tree a -> Tree b -> Bool
mirror Tree a
left Tree a
right

mirror :: Tree a -> Tree b -> Bool
mirror :: forall a b. Tree a -> Tree b -> Bool
mirror Tree a
Empty Tree b
Empty                     = Bool
True
mirror (Branch a
_ Tree a
l Tree a
r) (Branch b
_ Tree b
l' Tree b
r') = Tree a -> Tree b -> Bool
forall a b. Tree a -> Tree b -> Bool
mirror Tree a
l Tree b
r' Bool -> Bool -> Bool
&& Tree a -> Tree b -> Bool
forall a b. Tree a -> Tree b -> Bool
mirror Tree a
r Tree b
l'
mirror Tree a
_ Tree b
_                             = Bool
False