From 907e258e69f64fce172b9c8ccb3164503ced2e5a Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
Date: Thu, 25 Dec 2014 08:51:44 +0530
Subject: [PATCH] simplify the code a bit

---
 hw7/JoinList.hs | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/hw7/JoinList.hs b/hw7/JoinList.hs
index 7a353cd..916597e 100644
--- a/hw7/JoinList.hs
+++ b/hw7/JoinList.hs
@@ -42,10 +42,11 @@ dropJ _ Empty = Empty
 dropJ n v@(Single _ _) | n == 0 = v
                        | otherwise = Empty
 dropJ n (Append t l r) | n > getSize (size t) = Empty
-                       | n > (getSize (size (tag l))) =
-                           dropJ (n - getSize (size (tag l))) r
+                       | n > leftSize =
+                           dropJ (n - leftSize) r
                        | otherwise = let lft = dropJ n l in
                                      Append ((tag lft) `mappend` (tag r)) lft r
+                       where leftSize = getSize . size . tag $ l
 
 -- 3. take
 takeJ :: (Sized b, Monoid b) =>
@@ -56,7 +57,8 @@ takeJ _ Empty = Empty
 takeJ n v@(Single _ _) | n == 0 = v
                        | otherwise = Empty
 takeJ n v@(Append t l r) | n > getSize (size t) = v
-                         | n < getSize (size (tag l)) = takeJ n l
-                         | otherwise = let rt = takeJ (n - getSize (size (tag l))) r in
+                         | n < leftSize = takeJ n l
+                         | otherwise = let rt = takeJ (n - leftSize) r in
                                        Append ((tag l) `mappend` (tag rt)) l rt
+                         where leftSize = getSize . size . tag $ l
 
-- 
2.45.2