Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- let (local variables for functions)
- myLetFunc a b c = let det = sqrt(b^2 - 4*a*c)
- in ((-b + det) / (2*a), (-b - det) / (2*a))
- -- where
- myWhereFunc a b c = ((-b + det) / twice_a, (-b-det) / twice_a)
- where det = sqrt (b*b-4*a*c)
- twice_a = 2*a
- -- dacva
- factorial 0 = 1
- factorial n | n < 0 = error "factorial: negative argument"
- | n >= 0 = n * factorial (n-1)
- signum x | x < 0 = -1
- | x > 0 = 1
- | otherwise = 0
- -- data
- data Color = Red | Green | Blue | RGB Int Int Int
- data Bool = True | False
- {-data a = Nothing | Just a
- gayofa 0 b = Nothing
- gayofa a b = Just (a / b)-}
- data Daytime = Morning | Afternoon | Evening | Night deriving (Eq, Show)
- -- Book Store
- data Product = Book String String | Video String | Cd String String Int
- getTitle :: Product -> String
- getTitle (Book a b) = a
- getTitle (Video a) = a
- getTitle (Cd a b c) = a
- getTitles :: [Product] -> [String]
- getTitles [] = []
- getTitles (x:xs) = getTitle x : getTitles xs
- bookAuthors :: [Product] -> [String]
- bookAuthors [] = []
- bookAuthors ((Book a b):xs) = a : bookAuthors(xs)
- lookupTitle :: String -> [Product] -> Maybe Product
- lookupTitle str [] = Nothing
- lookupTitle str (x:xs) = if (getTitle x == str) then Just x else lookupTitle str xs
- lookupTitles :: [String] -> [Product] -> [Maybe Product]
- lookupTitles [] _ = []
- lookupTitles _ [] = []
- lookupTitles (s:str) xs = lookupTitle s xs : lookupTitles str xs
- -- Trees
- data Tree a = Leaf a | Branch (Tree a) (Tree a)
- treeSize (Leaf _) = 1
- treeSize (Branch l r) = treeSize l + treeSize r
- leafList (Leaf x) = [x]
- leafList (Branch l r) = leafList l ++ leafList r
- -- magali rigis funkciebi
- -- foldr (-) 0 [1,2,3] daabrunebs (1-(2-(3-0))) = 2
- -- foldl (-) 0 [1,2,3] daabrunebs (((0-1)-2)-3) = -6
- listAverage xs = foldr (+) 0 xs / (sizeOfList xs)
- sizeOfList [] = 0
- sizeOfList (x:xs) = sizeOfList xs + 1
- skalarOfLists xs ys = foldr (+) 0 (zipWith (*) xs ys)
- countEven xs = filter even xs
- quicksort :: Ord a => [a] -> [a]
- quicksort [] = []
- quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater)
- where
- lesser = filter (< p) xs
- greater = filter (>= p) xs
- quicksort2 p (xs) = [x | x<-quicksort xs, p x]
- quicksort3 p xs = filter p (quicksort xs)
- -- map aketebs moqmedebas siis yvela elementistvis
- doJami xs = map (+1) xs
- --gamosaxet [f x | x<xs, px] map-it da filter-it
- mySuperFunc p f xs = map f (filter p xs)
- -- type (tipis gamocxadeba)
- type String = [Char]
- type Pos = (Int, Int)
- origin :: Pos
- origin = (0,0)
- type Pair a = (a, a)
- mult :: Pair Int -> Int
- mult (m, n) = m*n
- -- binaruli xe
- data Tree = Leaf Int | Node Tree Int Tree
- occurs :: Int -> Tree -> Bool
- occurs a (Leaf b) = (a==b)
- occurs a (Node l b r) = ((a==b) || (occurs a l) || (occurs a r))
- flatten :: Tree -> [Int]
- flatten (Leaf n) = [n]
- flatten (Node l n r) = (flatten l) ++ [n] ++ (flatten r)
Advertisement
Add Comment
Please, Sign In to add comment