{-# OPTIONS -XTypeSynonymInstances #-}
import Test.QuickCheck
import List
data Tree a = Leaf a | Node (Tree a) (Tree a)
	      deriving Show

reverseTree :: Tree a -> Tree a
reverseTree t =
	case t of
		Leaf a -> Leaf a
		Node t1 t2 -> Node (reverseTree t2) (reverseTree t1)

treeEQ :: (a->a->Bool) -> Tree a -> Tree a -> Bool
treeEQ eq (Leaf a) (Leaf b) = (eq a b)
treeEQ eq (Leaf a) (Node t3 t4) = False
treeEQ eq (Node t1 t2) (Leaf b) = False
treeEQ eq (Node t1 t2) (Node t3 t4) = (treeEQ eq t1 t3)&&(treeEQ eq t2 t4)

prop_revTreeTest :: TS -> Bool
prop_revTreeTest tree = treeEQ (==) (reverseTree (reverseTree tree)) tree

type TS = Tree Int
instance Arbitrary TS where
    arbitrary = do
      n <- choose (1,2) :: Gen Int
      case n of
        1 -> do i <- arbitrary
                return (Leaf i)
        2 -> do t1 <- arbitrary
                t2 <- arbitrary
                return (Node t1 t2)

{-
invoke "ghci section.hs" on command line 

Here are the lines that I typed into ghci.

reverseTree (Node (Leaf 1) (Node (Leaf 2) (Leaf 3)))
quickCheck prop_revTreeTest 
-} 