Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main :: IO()
- main = do
- print $ "hello world"
- data Color = Yellow | Green | Blue | Red
- data PeaNum - Succ PeaNum | Zero
- data Calculation = Add Int Int | Sub Int Int | Mul Int Int | Div Int Int
- calc :: Calculation -> Int
- calc (Add x y) = x + y
- calc (Sub x y) = x - y
- calc (Mul x y) = x * y
- calc (Div x y) = x / y
- data PeaNum = Succ PeaNum | Zero
- data Tree a = Leaf | Node (Tree a) a (Tree a)
- four :: PeaNum
- four = Succ $ Succ $ Succ $ Zero
- tree :: Tree Int
- tree = Node (Node Leaf 1 Leaf) 2 (Node (Node Leaf 3 Leaf) 4 Leaf)
- decSort = reverse . sort
- decSort = (\x -> reverse (sort x))
- decSort x = reverse (sort x)
- map2D :: (a -> b) -> [[a]] -> [[b]]
- map2D = map . map
- -- these functions down there are equivalent to map2D
- map2D = (\f1 xs -> map f1 xs) . (\f2 ys -> map f2 ys)
- map2D = (\x -> (\f1 xs -> map f1 xs) ((\f2 ys -> map f2 ys) x))
- map2D x = (\f1 xs -> map f1 xs) ((\f2 ys -> map f2 ys) x)
- map2D x = (\f1 xs -> map f1 xs) ((\ys -> map x ys)
- map2D x = (\xs -> map (\ys -> map x ys) xs)
- map2D f xs = map (\ys -> map f ys) xs
- -- btw, map takes the function and the list (so we have map2D f xs, it's clear)
- f xs = map (\x -> x + 1) (filter (\x -> x > 1) xs)
- data List = Empty | Cons Int (List)
- data List a = Empty | Cons a (List)
- toHList :: List a -> [a]
- toHList Empty = []
- toHList (Cons x xs) = x : toHList xs
- map' f [] = []
- map' f (x:xs) = f x : map' f xs
- data Error a = Error | Ok a
- safeDivide :: Error Int -> Error Int -> Error Int
- safeDivide (Error) _ = Error
- safeDivide _ (Error) = Error
- safeDivide (Ok a) (Ok 0) = Error
- safeDivide (Ok a) (Ok b) = Ok (a `div` b)
- data Person = Person String Int (Int, Int, Int) -- Person Name Age ID
- getDateOrBirth (Person _ _ (dob) = dob)
- -- algebric types always starts with data (тип с определен брой компоненти)
- data Day = Monday | Tuesday | Wendsday | Thursday | Friday | Saturday | Sunday
- data Temp = Cold | Hot
- data Season = Spring | Summer | Autumn | Winter
- weather :: Season -> Temp
- weather Spring = Hot
- weather _ = Cold
- data People = Person Name Age
- -- тук Name е синоним на String, а Age е синоним на Int
- type Name = String
- type Age = Int
- -- example for values of type People
- -- Person "Aunt Jemima" 77
- -- Person "Ronnie" 14
- data Shape = Circle Float | Rectangle Float Float
- -- Circle 3.0
- -- Rectangle 45.9 87.6
- isRound :: Shape -> Bool
- isRound (Circle _) = True
- isRound (Rectangle _ _) = Flase
- area :: Shape -> Float
- area (Circle r) = pi*r*r
- area (Rectangle a b) = a*b
- data Season = Spring | Summer | Autumn | Winter
- deriving (Eq, Ord, Enum, Show, Read)
- data Shape = Circle Float |
- Rectangle Float Float
- deriving (Eq, Show, Read)
- data Expr = Lit Int |
- Add Expr Expr |
- SUb Expr Expr
- -- a little bit about trees, i am not sure if this is included in my homework, but i'll write it, nothing costs
- date NTree = NilT |
- Node Int NTree NTree
- sumTree, depth :: NTree -> Int
- sumTree NilT = 0
- sumTree (Node n t1 t2) = n + sumTree t1 + sumTree t2
- depth NilT = 0
- depth (Node n t1 t2) = 1 + max (depth t1) (depth t2)
- occurs :: NTree -> Int -> Int
- occurs NilT p = 0
- occurs (Node n t1 t2) p
- | n == p = 1 + occurs t1 p + occurs t2 p
- | otherwise = occurs t1 p + occurs t2 p
- data Person = Adult Name Address Biog |
- Child Name
- data Biog = Parent String [Person] |
- NonParent String
- showPerson (Adult nm ad bio)
- = show nm ++ show ad ++ showBiog bio
- ...
- showBiog (Parent st parList)
- = st ++ concat (map showPerson parList)
- ...
- data Pairs a = Pr a a
- -- Pr 2 3 :: Pairs Int
- -- Pr [] [3] :: Pairs [Int]
- -- Pr [] [] :: Pairs [a]
- equalPair :: Eq a => Pairs a -> Bool
- equalPair (Pr x y) = (x == y)
- data List a = NilList | Cons a (List a)
- deriving (Eq, Show, Read)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement