Minor code cleanup on HW1.
This commit is contained in:
parent
739ea0d1ad
commit
dbd1e17b2a
|
@ -29,7 +29,7 @@ treeFoldr f a (Node i l r) = treeFoldr f (f i (treeFoldr f a r)) l
|
|||
|
||||
-- | foldr for non-empty lists.
|
||||
treeFoldr1 :: (Int -> Int -> Int) -> Tree -> Int
|
||||
treeFoldr1 f (Leaf i) = i
|
||||
treeFoldr1 _ (Leaf i) = i
|
||||
treeFoldr1 f (Node i l r) = treeFoldr f (f i (treeFoldr1 f r)) l
|
||||
|
||||
-- | Left associative fold.
|
||||
|
@ -39,7 +39,7 @@ treeFoldl f a (Node i l r) = treeFoldl f (f i (treeFoldl f a l)) r
|
|||
|
||||
-- | foldl for non-empty lists.
|
||||
treeFoldl1 :: (Int -> Int -> Int) -> Tree -> Int
|
||||
treeFoldl1 f (Leaf i) = i
|
||||
treeFoldl1 _ (Leaf i) = i
|
||||
treeFoldl1 f (Node i l r) = treeFoldl f (f i (treeFoldl1 f l)) r
|
||||
|
||||
-- | In-order traversal fold.
|
||||
|
@ -62,7 +62,7 @@ treeFold f a (Node i l r) = f i $ treeFold f (treeFold f a r) l
|
|||
-- 1
|
||||
--
|
||||
leftmost :: Tree -> Int
|
||||
leftmost = treeFoldr1 (\i _ -> i)
|
||||
leftmost = treeFoldr1 const
|
||||
|
||||
-- | The integer at the right-most node of a binary tree.
|
||||
--
|
||||
|
@ -79,7 +79,7 @@ leftmost = treeFoldr1 (\i _ -> i)
|
|||
-- 9
|
||||
--
|
||||
rightmost :: Tree -> Int
|
||||
rightmost = treeFoldl1 (\i _ -> i)
|
||||
rightmost = treeFoldl1 const
|
||||
|
||||
-- | Get the maximum integer from a binary tree.
|
||||
--
|
||||
|
|
Loading…
Reference in New Issue
Block a user