| Append m (JoinList m a) (JoinList m a)
deriving (Eq, Show)
+jlToList :: JoinList m a -> [a]
+jlToList Empty = []
+jlToList (Single m a) = [a]
+jlToList (Append m lt rt) = jlToList lt ++ jlToList rt
+
-- exercise 1
tag :: Monoid m => JoinList m a -> m
tag (Empty) = mempty
instance Buffer (JoinList (Score, Size) String) where
- toString (Empty) = ""
- toString (Single _ s) = s
- toString (Append _ l r) = toString l ++ toString r
+ toString = unlines . jlToList
- fromString s = Single (scoreString s, (Size (length s))) s
+ fromString s = let ls = lines s in
+ foldr (+++) Empty $ map (\x -> Single (scoreString x, Size 1) x) ls
line n b = indexJ n b
replaceLine n l b = let pre = takeJ (n - 1) b
post = dropJ n b