Add the haskell book
This commit is contained in:
40
Haskell-book/11/Vehicle.hs
Normal file
40
Haskell-book/11/Vehicle.hs
Normal file
@@ -0,0 +1,40 @@
|
||||
module Vehicle where
|
||||
|
||||
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 = Car Mini (Price 14000)
|
||||
urCar = Car Mazda (Price 20000)
|
||||
clownCar = Car Tata (Price 7000)
|
||||
doge = Plane PapuAir (Size 1234)
|
||||
|
||||
isCar :: Vehicle -> Bool
|
||||
isCar (Car _ _) = True
|
||||
isCar _ = False
|
||||
|
||||
isPlane :: Vehicle -> Bool
|
||||
isPlane (Plane _ _) = True
|
||||
isPlane _ = False
|
||||
|
||||
areCars :: [Vehicle] -> [Bool]
|
||||
areCars = map isCar
|
||||
|
||||
getManu :: Vehicle -> Manufacturer
|
||||
getManu (Car m _) = m
|
||||
|
||||
data Example = MakeExample Int deriving Show
|
||||
Reference in New Issue
Block a user