From: Ramakrishnan Muthukrishnan Date: Wed, 24 Dec 2014 17:01:35 +0000 (+0530) Subject: hw7: exersize 2, part 2 X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/uri/flags/statistics?a=commitdiff_plain;h=047b4b4c62acc625ecae744572bbec1ea0a861ae;p=yorgey.git hw7: exersize 2, part 2 --- diff --git a/hw7/JoinList.hs b/hw7/JoinList.hs index 6ef51a8..b7a4aeb 100644 --- a/hw7/JoinList.hs +++ b/hw7/JoinList.hs @@ -30,3 +30,14 @@ indexJ _ (Single _ a) = Just a indexJ n (Append _ l r) | 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 0 x = x +dropJ _ Empty = Empty +dropJ _ (Single _ _) = Empty +dropJ n x | (getSize (size (tag x))) < n = Empty +dropJ n (Append _ l r) | 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