1
1
main :: IO ()
2
2
main = do
3
- putStr $ unlines $ list !! 0
4
- putStr $ unlines $ dent <$> (rewrap $ wrap <$> list )
5
- putStr $ unlines $ list !! 1
3
+ putStr $ unlines $ file !! 0
4
+ putStr $ unlines $ dent <$> (rewrap $ wrap . (escape <$> ) <$> file )
5
+ putStr $ unlines $ file !! 1
6
6
7
- list :: [[String ]]
8
- list =
7
+ file :: [[String ]]
8
+ file =
9
9
[[" main :: IO ()"
10
10
," main = do"
11
- ," putStr $ unlines $ list !! 0"
12
- ," putStr $ unlines $ dent <$> (rewrap $ wrap <$> list )"
13
- ," putStr $ unlines $ list !! 1"
11
+ ," putStr $ unlines $ file !! 0"
12
+ ," putStr $ unlines $ dent <$> (rewrap $ wrap . (escape <$>) <$> file )"
13
+ ," putStr $ unlines $ file !! 1"
14
14
," "
15
- ," list :: [[String]]"
16
- ," list ="
15
+ ," file :: [[String]]"
16
+ ," file ="
17
17
]
18
18
,[" "
19
19
," dent :: String -> String"
20
20
," dent = (\" \" ++)"
21
21
," "
22
22
," rewrap :: [[String]] -> [String]"
23
- ," rewrap [] = [\" []\" ]"
24
- ," rewrap (l:ls) = app \" ]\" $ (pure l >>= pre \" [\" ) ++ (ls >>= pre \" ,\" )"
23
+ ," rewrap = concat . pre (pre (\" [\" ++)) . fil (pre (\" ,\" ++)) . app (app (++ \" ]\" ))"
25
24
," "
26
- ," pre :: [a] -> [[a]] -> [[a]]"
27
- ," pre x [] = [x ]"
28
- ," pre x (s:ss ) = [x ++ s ] ++ ss "
25
+ ," pre :: ( [a] -> [a]) -> [[a]] -> [[a]]"
26
+ ," pre f [] = [f [] ]"
27
+ ," pre f (x:xs ) = [f x ] ++ xs "
29
28
," "
30
- ," fil :: [a] -> [[a]] -> [[a]]"
31
- ," fil x [] = []"
32
- ," fil x (s:ss ) = [s ] ++ ((x ++) <$> ss )"
29
+ ," fil :: ( [a] -> [a]) -> [[a]] -> [[a]]"
30
+ ," fil _ [] = []"
31
+ ," fil f (x:xs ) = [x ] ++ (f <$> xs )"
33
32
," "
34
- ," app :: [a] -> [[a]] -> [[a]]"
35
- ," app x [] = [x ]"
36
- ," app x [t ] = [t ++ x]"
37
- ," app x (s:ss ) = [s ] ++ app x ss "
33
+ ," app :: ( [a] -> [a]) -> [[a]] -> [[a]]"
34
+ ," app f [] = [f [] ]"
35
+ ," app f [x ] = [f x]"
36
+ ," app f (x:xs ) = [x ] ++ app f xs "
38
37
," "
39
38
," wrap :: [String] -> [String]"
40
- ," wrap ss = (fil \" , \" $ pre \" [ \" $ escape <$> ss) ++ [\" ]\" ]"
39
+ ," wrap ss = (pre ( \" [ \" ++) $ fil ( \" , \" ++) $ ss) ++ [\" ]\" ]"
41
40
," "
42
41
," escape :: String -> String"
43
42
," escape s = [qot] ++ (s >>= escChar) ++ [qot]"
@@ -55,24 +54,23 @@ dent :: String -> String
55
54
dent = (" " ++ )
56
55
57
56
rewrap :: [[String ]] -> [String ]
58
- rewrap [] = [" []" ]
59
- rewrap (l: ls) = app " ]" $ (pure l >>= pre " [" ) ++ (ls >>= pre " ," )
57
+ rewrap = concat . pre (pre (" [" ++ )) . fil (pre (" ," ++ )) . app (app (++ " ]" ))
60
58
61
- pre :: [a ] -> [[a ]] -> [[a ]]
62
- pre x [] = [x ]
63
- pre x (s : ss ) = [x ++ s ] ++ ss
59
+ pre :: ( [a ] -> [ a ]) -> [[a ]] -> [[a ]]
60
+ pre f [] = [f [] ]
61
+ pre f (x : xs ) = [f x ] ++ xs
64
62
65
- fil :: [a ] -> [[a ]] -> [[a ]]
66
- fil x [] = []
67
- fil x (s : ss ) = [s ] ++ ((x ++ ) <$> ss )
63
+ fil :: ( [a ] -> [ a ]) -> [[a ]] -> [[a ]]
64
+ fil _ [] = []
65
+ fil f (x : xs ) = [x ] ++ (f <$> xs )
68
66
69
- app :: [a ] -> [[a ]] -> [[a ]]
70
- app x [] = [x ]
71
- app x [t ] = [t ++ x]
72
- app x (s : ss ) = [s ] ++ app x ss
67
+ app :: ( [a ] -> [ a ]) -> [[a ]] -> [[a ]]
68
+ app f [] = [f [] ]
69
+ app f [x ] = [f x]
70
+ app f (x : xs ) = [x ] ++ app f xs
73
71
74
72
wrap :: [String ] -> [String ]
75
- wrap ss = (fil " , " $ pre " [ " $ escape <$> ss) ++ [" ]" ]
73
+ wrap ss = (pre ( " [ " ++ ) $ fil ( " , " ++ ) $ ss) ++ [" ]" ]
76
74
77
75
escape :: String -> String
78
76
escape s = [qot] ++ (s >>= escChar) ++ [qot]
0 commit comments