module JoinList where
import Data.Monoid
-
+import Sized
data JoinList m a = Empty
| Single m a
x +++ Empty = x
alst1 +++ alst2 = Append ((tag alst1) `mappend` (tag alst2)) alst1 alst2
+-- exercise 2
+-- 1. index
+indexJ :: (Sized b, Monoid b) =>
+ Int -> JoinList b a -> Maybe a
+indexJ _ Empty = Nothing
+indexJ n _ | n < 0 = Nothing
+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
+