-
Notifications
You must be signed in to change notification settings - Fork 0
/
chapter-3.hs
94 lines (69 loc) · 1.37 KB
/
chapter-3.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
-- Chapter 3 exercises
-- Exercises: Scope
-- 1 - Yes
-- 2 - No
-- 3 - No
-- 4 - Yes
-- Exercises: Syntax Errors
-- 1 - No. Correct syntax : (++) [1, 2, 3] [4, 5, 6]
-- 2 - No. Correct syntax : "<3" ++ " Haskell"
-- 3 - Yes.
-- Chatper Exercises
-- Reading syntax
-- 1
-- a - Yes
-- b - No - (++) [1, 2, 3] [4, 5, 6]
-- c - Yes
-- d - No - "hello" ++ "world"
-- e - No - "hello" !! 4
-- f - Yes
-- g - No - take 4 "lovely"
-- h - Yes
-- 2
-- a - d
-- b - c
-- c - e
-- d - a
-- e - b
-- Building functions
-- 1
-- a
-- "Curry is awesome" ++ "!"
-- b
-- "Curry is awesome!" !! 4
-- c
-- drop 9 "Curry is awesome!"
-- 2
-- a
-- exclaim x = x ++ "!"
-- b
-- getFourthIndex x = x !! 4
-- c
-- dropNine x = drop 9 x
-- 3
-- thirdLetter :: String -> Char
-- thirdLetter x = x !! 2
--4
-- letterIndex :: Int -> Char
-- letterIndex i = "Curry is awesome!" !! i
-- 5
-- rvrs x =
-- let
-- firstWord = take 5 x
-- secondWord = take 2 $ drop 6 x
-- thirdWord = drop 9 x
-- in
-- thirdWord ++ " " ++ secondWord ++ " " ++ firstWord
-- All the above exercises are commented so that the following one works.
-- 6
module Reverse where
rvrs :: String -> String
rvrs x =
let
firstWord = take 5 x
secondWord = take 2 $ drop 6 x
thirdWord = drop 9 x
in
thirdWord ++ " " ++ secondWord ++ " " ++ firstWord
main :: IO ()
main = print $ rvrs "Curry is awesome"