-
Notifications
You must be signed in to change notification settings - Fork 0
/
poemlines.hs
38 lines (31 loc) · 1.07 KB
/
poemlines.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
module PoemLines where
firstSen = "Tyger Tyger, burning bright\n"
secondSen = "In the forests of the night\n"
thirdSen = "What immortal hand or eye\n"
fourthSen = "Could frame thy fearful symmetry?"
sentences = firstSen ++ secondSen ++ thirdSen ++ fourthSen
notNewLine :: Char -> Bool
notNewLine = (/=)'\n'
myLines :: String -> [String]
myLines s = go s []
where go [] xs = xs
go s' xs = go rest $ xs ++ [nextWord]
where nextWord = (takeWhile notNewLine s')
rest = drop 1 (dropWhile notNewLine s')
myLinesOn :: (Eq a) => [a] -> a -> [[a]]
myLinesOn s c = go s []
where pred = (/=)c
go [] xs = xs
go s' xs = go rest result
where nextWord = (takeWhile pred s')
result = xs ++ [nextWord]
rest = drop 1 (dropWhile pred s')
shouldEqual =
[ "Tyger Tyger, burning bright"
, "In the forests of the night"
, "What immortal hand or eye"
, "Could frame thy fearful symmetry?"
]
main :: IO ()
main =
print $ "Are they equal?" ++ show (myLines sentences == shouldEqual)