Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Main where
- type Title = String
- type Videolist = [(Title,(Int,Int))] --[(title,(available,rent))]
- movies::Videolist
- movies = [("Am Limit",(1,0)), ("Kill Bill vol. 1", (3,1)),("Matrix",(2,2)),("Das Matterhorn",(3,1))]
- rentable :: Title -> Videolist -> Bool
- rentable _ [] = False
- rentable title ((t,(a,r)):rest) = if title == t then a>r else rentable title rest
- hasFilm :: Title -> Videolist -> Bool
- hasFilm _ [] = False
- hasFilm title ((t,(_,_)):rest) = (t == title) || hasFilm title rest
- rent:: Title -> Videolist -> Videolist
- rent _ [] = error "Film nicht vorhanden"
- rent x ((t,(a,r)):rest) | not (hasFilm x ((t,(a,r)):rest)) = error "Film nicht vorhanden"
- | not (rentable x ((t,(a,r)):rest)) = error "Film nicht verfuegbar"
- | otherwise = if x == t then (t,(a,r+1)):rest else (t, (a, r)) : rent x rest
- addFilm::Title -> Videolist -> Videolist
- addFilm title [] = [(title, (1, 0))]
- addFilm title ((t,(a,r)):rest) = if title == t then (t,(a+1,r)):rest else (t, (a, r)) : addFilm title rest
- insert:: Title -> Videolist -> (Videolist,Bool)
- insert title liste | not (hasFilm title liste) = ((title, (1, 0)) : liste,False)
- | otherwise = (addFilm title liste,True)
- showVideolistItem::Title -> Videolist -> String
- showVideolistItem _ [] = "Film nicht in der Liste"
- showVideolistItem title ((t,(a,r)):rest) = if title == t
- then t ++ " (" ++ show r ++
- " Exemplare verliehen, " ++
- (if a == r then "keine" else show (a - r) ) ++ " Exemplare auf Lager)"
- else showVideolistItem title rest
- state :: Videolist -> (Int, Int)
- state [] = (0,0)
- state ((_,(a,r)):rest) = ??
- main::IO()
- main = do
- putStr "search Am Limit"
Add Comment
Please, Sign In to add comment