-
Notifications
You must be signed in to change notification settings - Fork 0
/
poemLines.hs
42 lines (35 loc) · 1.09 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
39
40
41
42
-- poemLines.hs
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
--putStrLen sentences -- should print
-- Tyger Tyger, burning bright
-- In the forests of the night
-- What immortal hand or eye
-- Could frame thy fearful symmetry?
mySplit :: String -> Char -> [String]
mySplit "" _ = []
mySplit x c = firstPart : mySplit remaining c
where firstPart = takeWhile (/=c) x
remaining = dropWhile (==c) $ dropWhile (/=c) x
-- Implement this
myLines :: String -> [String]
myLines x = mySplit x '\n'
-- What we want 'myLines sentences' to equal
shouldEqual =
[ "Tyger Tyger, burning bright"
, "In the forests of the night"
, "What immortal hand or eye"
, "Could frame thy fearful symmetry?"
]
-- The main function here is a small test
-- to ensure you've written your function
-- correctly.
main :: IO ()
main =
print $ "Are they equal? "
++ show (myLines sentences == shouldEqual)