-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path20150407.hs
53 lines (41 loc) · 1.31 KB
/
20150407.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
data Shape = Circle Float | Rectangle Float Float
area :: Shape -> Float
area (Circle r) = r * r * pi
area (Rectangle l1 l2) = l1 * l2
data Dias = Domingo | Segunda Int [String]| Terca Int [String] | Quarta Int [String] | Quinta Int [String] | Sexta Int [String] | Sabado
isWeekDay :: Dias -> Bool
isWeekDay (Domingo) = True
isWeekDay (Sabado) = True
isWeekDay _ = False
isPLC :: Dias -> Bool
isPLC (Domingo) = False
isPLC (Sabado) = False
isPLC (Segunda h ls) = checkPLC ls
isPLC (Terca h ls) = checkPLC ls
isPLC (Quarta h ls) = checkPLC ls
isPLC (Quinta h ls) = checkPLC ls
isPLC (Sexta h ls) = checkPLC ls
checkPLC :: [String] -> Bool
checkPLC (x : xs)
| x == "PLC" = True
| xs == [] = False
| otherwise = checkPLC xs
data Tree t = NilT | Node t (Tree t) (Tree t)
deriving (Eq, Show)
data Expr = Lit Int | Add Expr Expr | Sub Expr Expr
deriving (Show)
showExpr :: Expr -> String
showExpr (Lit a) = show(a)
showExpr (Add a b) = showExpr(a) ++ "+" ++ showExpr(b)
showExpr (Sub a b) = showExpr(a) ++ "-" ++ showExpr(b)
data List t = Nil | Cons t (List t)
deriving (Show)
toList :: List t -> [t]
toList (Nil) = []
toList (Cons a ls) = a:toList(ls)
fromList :: [t] -> List t
fromList [] = Nil
fromList (a:as) = Cons a (fromList as)
depth :: Tree t -> Int
depth (NilT) = 0
depth (Node a b c) = 1 + (max (depth b) (depth c))