Guest User

Untitled

a guest
Aug 5th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Main where
  2.  
  3. type Title = String
  4. type Videolist = [(Title,(Int,Int))] --[(title,(available,rent))]
  5.  
  6. movies::Videolist
  7. movies = [("Am Limit",(1,0)), ("Kill Bill vol. 1", (3,1)),("Matrix",(2,2))]
  8.  
  9. rentable :: Title -> Videolist -> Bool
  10. rentable _ [] =  False
  11. rentable title ((t,(a,r)):rest) = if title == t then a>r else rentable title rest
  12.  
  13. hasFilm :: Title -> Videolist -> Bool
  14. hasFilm _ [] = False
  15. hasFilm title ((t,(_,_)):rest) = (t == title) || hasFilm title rest
  16.  
  17. rent:: Title -> Videolist -> Videolist
  18. rent _ [] = error "Film nicht vorhanden"
  19. rent x ((t,(a,r)):rest) | not (hasFilm x ((t,(a,r)):rest)) = error "Film nicht vorhanden"
  20.                         | not (rentable x ((t,(a,r)):rest)) = error "Film nicht verfuegbar"
  21.                         | otherwise = if x == t then (t,(a,r+1)):rest else (t, (a, r)) : rent x rest
  22.  
  23.  
  24.  
  25. insert:: Title -> Videolist -> (Videolist,Bool)
  26. --insert title [] = ([(title,(1,0))],False)
  27. insert title ((t,(a,r)):rest) | not (hasFilm title ((t,(a,r)):rest) )  = ((title, (1, 0)) : ((t, (a, r)) : rest),False)
  28.                               | otherwise = if title == t then ((t,(a+1,r)):rest, True) else insert title rest
  29.  
  30. main::IO()
  31. main = do
  32.         putStr "search Am Limit"
Add Comment
Please, Sign In to add comment