-
Notifications
You must be signed in to change notification settings - Fork 0
/
seven.hs
139 lines (86 loc) · 2 KB
/
seven.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
module Seven where
import Data.List
--null,take,drop,fst,snd,length,max,min,head,tail,
--sum,and,product,or,reverse,init,last,
--zip,delete,deleteAll,zip3,replicate,concat,dropWhile,takeWhile
fst' (a, b) = a
snd' (a, b) = b
drop' _ [] = []
drop' 0 xs = xs
drop' n (x:xs) = drop' (n-1) xs
--drop' 1312216 [] = []
--drop' 0 [1..10] = [1,2,3,4,5,6,7,8,9,10]
--drop' 3 [1..10] = [4,5,6,7,8,9,10]
take' _ [] = []
take' 0 xs = []
take' n (x:xs) = [x] ++ (take' (n-1) xs)
--take' 1442312 [] = []
--take' 0 [1,2,3] = [1,2,3]
head' :: [a] -> a
head' (x:xs) = x
length' :: [a] -> Integer
length' [] = 0
length' (x:xs) = 1 + (length' xs)
--length' [1,2,3] = 3
-- 1 + length' [2,3] -> 1+2
-- 1 + length' [3] -> 1+1
-- 1 + 0
--length' [[]] = 1
--length' [] = 0
tail' :: [a] -> [a]
tail' (x:xs) = xs
sum' [] = 0
sum' (x:xs) = x + (sum' xs)
--sum' [1,2,3] => 1 + sum' [2,3] => 1 + 5
--sum' [2,3] => 2 + sum' [3] => 2 + 3
--sum' [3] = 3 + sum [0]
max' a b
| a > b = a
| a < b = b
min' a b
| a < b = a
| a > b = b
null' x
| x == [] = True
| otherwise = False
--null [] = True
--null [-1] = False
--null [1] = False
--null [0] = False
init' [x] = []
init' (x:xs) = x : init' (xs)
--init' [0] = []
--init' [1..10] = [1,2,3,4,5,6,7,8,9]
or'[] = False
or' [False,False] = False
or' [True,False] = True
or' [False,True] = True
or' [True,True] = True
--[False,False] = False
--[True,False] = True
--[False,True] = True
--[True,True] = True
and' [] = True
and' [True,True] = True
and' [True,False] = False
and' [False,True] = False
and' [False,False] = False
product' [] = 1
product' [0] = 0
product' (x:xs) = x * (product' xs)
--product' [1,2,3] = 6
--product' 1*2*3 = 6
delete' _ [] = []
delete' 0 (x:xs) = xs
delete' n (x:xs) =
reverse' [] = []
reverse' [n] = [n]
reverse' (x:xs) = reverse' xs ++ [x]
last' [n] = n
last' (x:xs) = last' xs
concat' [] = []
--unfinish
zip' [] [] = []
--unfinish
minimum' [n] = n
--unfinish