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))]
- 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
- insert:: Title -> Videolist -> (Videolist,Bool)
- --insert title [] = ([(title,(1,0))],False)
- insert title ((t,(a,r)):rest) | not (hasFilm title ((t,(a,r)):rest) ) = ((title, (1, 0)) : ((t, (a, r)) : rest),False)
- | otherwise = if title == t then ((t,(a+1,r)):rest, True) else insert title rest
- main::IO()
- main = do
- putStr "search Am Limit"
Add Comment
Please, Sign In to add comment