Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.Char
- a = [2*n | n <- [1,2,3,4]]
- b = [2*n-1 | n <- [1,2,3,4]]
- c = [even n | n <- [2, 4, 7, 8]]
- d = [odd n | n <- [2, 4, 7, 8]]
- e = [2*n | n <- [2, 4, 5, 7, 8], even n, n > 3]
- f = [2^n | n <- [21, 14, 5, 7, 8], odd n, n > 6]
- g = [sqrt n | n <- [1..20]]
- h = [(x, y) | x <- [1, 2, 3], y <- ['a', 'b', 'c', 'd']]
- sumPairs :: [(Int, Int)] -> [Int]
- sumPairs pairsList = [x + y | (x, y) <- pairsList]
- isDigit :: Char -> Bool
- isDigit ch = ch >= '0' && ch <= '9'
- isLetter :: Char -> Bool
- isLetter letter = (letter >= 'a' && letter <= 'z') || (letter >= 'A' && letter <= 'Z')
- allDigits :: String -> (Char -> Bool) -> String
- allDigits str option = [ch | ch <- str, option ch]
- toUpperMy :: Char -> Char
- toUpperMy ch = chr (ord ch + ord 'A' - ord 'a')
- exor :: Bool -> Bool -> Bool
- exor x y = (x && not y) || (not x && y)
- filterMy :: (Int->Bool) -> [Int] -> [Int]
- filterMy p [] = []
- filterMy p (x:xs)
- | p x = x : filterMy p xs
- | otherwise = filterMy p xs
- {-
- mapMy :: (a -> b) -> [a] -> [b]
- mapMy f [] = []
- mapMy f (x:xs) = (f x) : (map f xs)
- -}
- mapMy :: (a -> b) -> [a] -> [b]
- mapMy f xs = [f x | x <- xs]
- zipWithMy :: (a -> b -> c) -> [a] -> [b] -> [c]
- zipWithMy f (a:as) (b:bs) = f a b : zipWithMy f as bs
- zipWithMy _ _ _ = []
- sumL :: [Int] -> Int
- sumL [] = 0
- sumL (x:xs) = x + sum xs
- productMy :: [Int] -> Int
- productMy [] = 1
- productMy (x:xs) = x * productMy xs
- andMy :: [Bool] -> Bool
- andMy [] = True
- andMy (x:xs) = x && (andMy xs)
- foldrMy :: (a -> b -> b) -> b -> [a] -> b
- foldrMy f z [] = z
- foldrMy f z (x:xs) = f x (foldrMy f z xs)
- repeated :: (a -> a) -> Int -> (a -> a)
- repeated f 1 = f
- repeated f n = \x -> f (repeated f (n - 1) x)
- derive :: (Float -> Float) -> Float -> (Float -> Float)
- derive f dx = \x -> (f (x + dx) - f x) / dx
- insert :: Int -> [Int] -> [Int]
- insert x [] = [x]
- insert x (y:ys)
- | x <= y = x:(y:ys)
- | otherwise = y : (insert x ys)
- insertSort :: [Int] -> [Int]
- insertSort [] = []
- insertSort (x:xs) = insert x (insertSort xs)
- qSort :: [Int] -> [Int]
- qSort [] = []
- qSort (x:xs) = qSort more ++ [x] ++ qSort less
- where
- less = filter (<x) xs
- more = filter (>=x) xs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement