-
Notifications
You must be signed in to change notification settings - Fork 0
/
chapter11.hs
79 lines (48 loc) · 1.45 KB
/
chapter11.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
data Doggies a = Husky a | Mastiff a deriving (Eq, Show)
data Bordeaux doge = Bordeaux doge
data Price = Price Integer deriving (Eq, Show)
data Size = Size Integer deriving (Eq, Show)
data Manufacturer = Mini | Mazda | Tata deriving (Eq, Show)
data Airline = PapuAir | CatapultsR'Us | TakeYourChancesUnited deriving (Eq, Show)
data Vehicle = Car Manufacturer Price | Plane Airline Size deriving (Eq, Show)
myCar :: Vehicle
myCar = Car Mini (Price 14000)
urCar :: Vehicle
urCar = Car Mazda (Price 20000)
clownCar :: Vehicle
clownCar = Car Tata (Price 7000)
doge :: Vehicle
doge = Plane PapuAir (Size 822)
isCar :: Vehicle -> Bool
isCar (Car _ _) = True
isCar _ = False
isPlane :: Vehicle -> Bool
isPlane (Plane _ _) = True
isPlane _ = False
areCars :: [Vehicle] -> [Bool]
areCars = map isCar
getManu :: Vehicle -> Maybe Manufacturer
getManu (Car m _) = Just m
getManu _ = Nothing
getSize :: Vehicle -> Maybe Size
getSize (Plane _ m) = Just m
getSize _ = Nothing
data Example = MakeExample deriving Show
data Example2 = MakeExample2 Int deriving Show
class TooMany a where
tooMany :: a -> Bool
instance TooMany Int where
tooMany n = n > 42
newtype Goats = Goats Int deriving Show
instance TooMany Goats where
tooMany (Goats n) = n > 43
data Weekday =
Monday
| Tuesday
| Wednesday
| Thursday
| Friday
--f Friday = "Miller Time"
data Testing
squish :: [[a]] -> [a]
squish = foldr (++) []