From: Ramakrishnan Muthukrishnan Date: Thu, 25 Dec 2014 03:21:44 +0000 (+0530) Subject: simplify the code a bit X-Git-Url: https://git.rkrishnan.org/pf/$rel_link?a=commitdiff_plain;h=907e258e69f64fce172b9c8ccb3164503ced2e5a;p=yorgey.git simplify the code a bit --- 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