From: Ramakrishnan Muthukrishnan Date: Thu, 25 Dec 2014 11:16:35 +0000 (+0530) Subject: bug fix. Convert into lines X-Git-Url: https://git.rkrishnan.org/pf/content/en/service/frontends/configuration.txt?a=commitdiff_plain;h=e7dce90a59e151a293c0fdc336ea01746e752386;p=yorgey.git bug fix. Convert into lines --- 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