> module LinesTest where > newLines :: String -> [String] > newLines = foldr f [] > f x xss | x == '\n' = "" : xss > | otherwise = g x xss > g x [] = [[x]] > g x (ys:yss) = (x:ys) : yss > newLines2 :: String -> [String] > newLines2 [] = [] > newLines2 (x:xs) = f x (newLines2 xs) > prelLines :: String -> [String] > prelLines "" = [] > prelLines s = let (l, s') = break (== '\n') s > in l : case s' of > [] -> [] > (_:s'') -> prelLines s'' > spanLines :: String -> [String] > spanLines "" = [] > spanLines s = let (l, s') = span (/= '\n') s > in l : case s' of > [] -> [] > (_:s'') -> spanLines s'' > spanLines3 :: String -> [String] > spanLines3 "" = [] > spanLines3 s = let (l, s') = span ('\n' /=) s > in l : case s' of > [] -> [] > (_:s'') -> spanLines3 s'' > text = "Science\nis true.\nDon't be misled\nby facts."