-
-
Save sasamijp/8e05c0fabf0048686a2302ea28586f57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my_reverse :: [a] -> [a] | |
my_reverse [] = [] | |
my_reverse [x] = [x] | |
my_reverse (x:xs) = (my_reverse xs) ++ [x] | |
my_min_elem :: (Ord a) => [a] -> a | |
my_min_elem [x] = x | |
my_min_elem (x:xs) | |
| x < head xs = my_min_elem ([x] ++ tail xs) | |
| otherwise = my_min_elem xs | |
find_index :: (Eq a) => [a] -> a -> Int | |
find_index l e = head [i | (i, x)<-zip [0..] l, x == e] | |
my_min :: (Ord a) => [a] -> Int | |
my_min [x] = 0 | |
my_min l = find_index l (my_min_elem l) | |
my_member :: (Eq a) => a -> [a] -> Bool | |
my_member x [] = False | |
my_member x l | |
| x == head l = True | |
| otherwise = my_member x (tail l) | |
prod :: [a] -> [a] -> [(a, a)] | |
prod [x] l = zip (replicate (length l) x) l | |
prod (x:xs) l = (prod [x] l) ++ prod xs l | |
my_sort :: (Ord a) => [a] -> [a] | |
my_sort [] = [] | |
my_sort (pivot:xs) = (my_sort left) ++ [pivot] ++ (my_sort right) | |
where | |
left = [x| x<-xs, x <= pivot] | |
right = [x| x<-xs, x > pivot] | |
main=do | |
print(my_sort [5,1,0,1,8]) | |
print(prod [1,2] [3,4]) | |
print(my_min [1,3,4,6,2,4, -1]) | |
print(my_member 4 [0, 6, 1]) | |
print(my_member 'a' "tuat") | |
print(my_reverse "TUAT") | |
print(True && (False || True)) | |
print(0 : 1 : 2 : []) | |
print(head (True : [False])) | |
print([True]: []) | |
print(head [4..]) | |
print([k+1|k<-[1..10], even k]) | |
print([[i, j] | i <- [1..2], j <- [1..4]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment