From e7dce90a59e151a293c0fdc336ea01746e752386 Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan Date: Thu, 25 Dec 2014 16:46:35 +0530 Subject: [PATCH] bug fix. Convert into lines --- hw7/JoinList.hs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hw7/JoinList.hs b/hw7/JoinList.hs index e5633d5..84c3a41 100644 --- a/hw7/JoinList.hs +++ b/hw7/JoinList.hs @@ -15,6 +15,11 @@ data JoinList m a = Empty | 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 @@ -83,11 +88,10 @@ scoreLine l = let scores = map scoreString . words $ l 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 -- 2.37.2