type TripId = Integer data Transport = Plane | Train | Bus | Ship deriving (Eq, Show) type Place = String type Price = Integer type Trip = (TripId, Transport, Place, Place, Price) type TicketId = Integer type PersonId = Integer data Tarif = Adult | Child | Student | Senior deriving (Eq, Show) type Ticket = (TicketId, PersonId, TripId, Tarif) type Database = ([Ticket], [Trip]) -- Gettery getTripId :: Trip -> TripId getTripId = undefined getTransport :: Trip -> Transport getTransport = undefined getPlaceFrom :: Trip -> Place getPlaceFrom = undefined getPlaceTo :: Trip -> Place getPlaceTo = undefined getPrice :: Trip -> Price getPrice = undefined getTicketId :: Ticket -> TicketId getTicketId = undefined getPersonId :: Ticket -> PersonId getPersonId = undefined getTicketTripId :: Ticket -> TripId getTicketTripId = undefined getTarif :: Ticket -> Tarif getTarif = undefined -- Funkce pracující s databází lookupTarif :: TicketId -> [Ticket] -> Tarif lookupTarif = undefined tripsFrom :: Place -> [Trip] -> [Trip] tripsFrom = undefined tripsTo :: Place -> [Trip] -> [Trip] tripsTo = undefined transports :: Place -> Place -> [Trip] -> [Transport] transports = undefined updatePrice :: TripId -> Price -> [Trip] -> [Trip] updatePrice = undefined tripCountByTransport :: Transport -> [Trip] -> Int tripCountByTransport = undefined travelsBy :: PersonId -> TripId -> [Ticket] -> Bool travelsBy = undefined peopleByTarif :: Tarif -> [Ticket] -> [PersonId] peopleByTarif = undefined travellersFrom :: Place -> Database -> [PersonId] travellersFrom = undefined ticketPrice :: (Tarif -> Price -> Price) -> TripId -> Tarif -> [Trip] -> Price ticketPrice = undefined spent :: (Tarif -> Price -> Price) -> PersonId -> Database -> Price spent = undefined ------------------------------------------------------------------------------- -- S A M P L E D A T A B A S E -- ------------------------------------------------------------------------------- testDB :: Database testDB = (tickets, trips) where tickets = [ (0, 42, 0, Student), (1, 42, 4, Student) , (5, 4, 2, Adult), (42, 142, 5, Child) ] trips = [ (0, Plane, "Brno", "Praha", 1000), (1, Plane, "Praha", "Brno", 1050) , (2, Train, "Brno", "Praha", 400), (3, Train, "Praha", "Brno", 450) , (4, Bus, "Bratislava", "Kosice", 351), (5, Ship, "Bergen", "Stavanger", 5000) ] tarifSR :: Tarif -> Price -> Price tarifSR Adult price = price tarifSR _ _ = 0 tarifCR :: Tarif -> Price -> Price tarifCR Adult price = price tarifCR Child _ = 0 tarifCR _ price = div (price * 3) 4 tarifNoDiscount :: Tarif -> Price -> Price tarifNoDiscount _ p = p