From 4e8d48f0e21062d9aeb7ab96fc6478560a421812 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
Date: Thu, 25 Dec 2014 08:37:47 +0530
Subject: [PATCH] hw7: rewrite dropJ

---
 hw7/JoinList.hs | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/hw7/JoinList.hs b/hw7/JoinList.hs
index 3dca2de..e498eed 100644
--- a/hw7/JoinList.hs
+++ b/hw7/JoinList.hs
@@ -33,3 +33,17 @@ indexJ n (Append t l r) | n >= getSize (size t) = Nothing
                         | n < (getSize (size (tag l))) = indexJ n l
                         | otherwise = indexJ (n - getSize (size (tag l))) r
 
+-- 2. drop
+dropJ :: (Sized b, Monoid b) =>
+         Int -> JoinList b a -> JoinList b a
+dropJ n x | n < 0 = x
+dropJ 0 x = x
+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
+                       | otherwise = let lft = dropJ n l in
+                                     Append ((tag lft) `mappend` (tag r)) lft r
+
-- 
2.45.2