From 9775b16492b2fd5f6cfc80619017df6e72ca9a8a Mon Sep 17 00:00:00 2001 From: Abdul Hanan Date: Wed, 28 Jul 2021 00:04:36 +0500 Subject: [PATCH] Improve Tree Arbitrary Improve Tree Arbitrary --- 21/21.12-instances-for-tree.hs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/21/21.12-instances-for-tree.hs b/21/21.12-instances-for-tree.hs index 620a7f8..e138224 100644 --- a/21/21.12-instances-for-tree.hs +++ b/21/21.12-instances-for-tree.hs @@ -23,11 +23,10 @@ instance Traversable Tree where traverse f (Node l x r) = Node <$> traverse f l <*> f x <*> traverse f r instance Arbitrary a => Arbitrary (Tree a) where - arbitrary = do - x <- arbitrary - y <- arbitrary - z <- arbitrary - return $ Node (Leaf x) y (Leaf z) + arbitrary = frequency [ + (1, return Empty) + ,(1, Leaf <$> arbitrary) + ,(1, Node <$> arbitrary <*> arbitrary <*> arbitrary)] instance Eq a => EqProp (Tree a) where (=-=) = eq