-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.hs
61 lines (42 loc) · 1.43 KB
/
Main.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
-- option 1 (https://github.com/PiotrJustyna/haskell-anywhere):
-- ./ghci.bat C:\Users\piotr_justyna\Documents\github\programming-in-haskell\part1_chapter3_exercise3
-- option 2 (stack):
-- stack ghci
-- option 3 (ghci):
-- ghci
--
-- :load Main
main = do
putStrLn "second [1, 2, 3]"
putStrLn . show $ second [1, 2, 3]
putStrLn "swap (1, 2)"
putStrLn . show $ swap (1, 2)
putStrLn "swap (1, \"2\")"
putStrLn . show $ swap (1, "2")
putStrLn "pair 1 \"2\""
putStrLn . show $ pair 1 "2"
putStrLn "double 1"
putStrLn . show $ double 1
putStrLn "palindrome [1, 2, 3, 4, 3, 2, 1]"
putStrLn . show $ palindrome [1, 2, 3, 4, 3, 2, 1]
putStrLn "twice twice (\\x -> x + 1) 1"
putStrLn . show $ twice (\x -> x + 1) 1
----------------------------------------
second :: Show a => [a] -> a
second xs = head (tail xs)
----------------------------------------
swap :: (Show a, Show b) => (a, b) -> (b, a)
swap (x,y) = (y,x)
----------------------------------------
pair :: (Show a, Show b) => a -> b -> (a, b)
pair x y = (x,y)
----------------------------------------
double :: Num a => a -> a
double x = x*2
----------------------------------------
palindrome :: Eq a => [a] -> Bool
palindrome xs = reverse xs == xs
----------------------------------------
twice :: (a -> a) -> a -> a
twice f x = f (f x)
----------------------------------------