-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMidare.hs
66 lines (52 loc) · 1.5 KB
/
Midare.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
module Midare where
import Prelude
{-
unlines :: String -> [String]
unlines x = go id x
where
go :: ([String] -> [String]) -> String -> [String]
go s [] = s [] : []
go s (xv : xs) = case xv of
'\n' -> s [] : go id xs
_ -> go (\y -> s (xv : y)) xs
lines :: [String] -> String
lines [] = []
lines (xv : xs) = go xv xs
where
go :: String -> [String] -> String
go xv [] = xv
go xv (xsv : xss) = case xv of
[] -> '\n' : go xsv xss
xvv : xvs -> xvv : go xvs (xsv : xss)
-- lines . unlines
unparagraphs :: [String] -> [[String]]
unparagraphs x = go id x
where
go :: ([[String]] -> [[String]]) -> [String] -> [[String]]
go s [] = s [] : []
go s (xv : xs) = case xv of
[] -> s [] : go id xs
_ -> go (\y -> s (xv : y)) xs
paragraphs :: [[String]] -> [String]
paragraphs [] = []
paragraphs (xv : xs) = go xv xs
where
go :: [String] -> [[String]] -> [String]
go xv [] = xv
go xv (xsv : xss) = case xv of
[] -> [] : go xsv xss
xvv : xvs -> xvv : go xvs (xsv : xss)
-}
data Lines = Cha Char Lines | New Break | End
data Break = Break Lines
unlines :: String -> Lines
unlines x = go id x
where
go :: (Lines -> Lines) -> String -> [String]
go s [] = s End
go s (xv : xs) = case xv of
'\n' -> s (New (Break (go id xs)))
_ -> go (\y -> s (Cha xv y)) xs
data Lines = Cha Char Lines | New Break | Prg Parag | End
data Break = Break Lines
data Parag = Parag Lines