Guest User

Untitled

a guest
Aug 5th, 2018
108
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)),("Das Matterhorn",(3,1))]
  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. addFilm::Title -> Videolist -> Videolist
  25. addFilm title [] = [(title, (1, 0))]
  26. addFilm title ((t,(a,r)):rest) = if title == t then (t,(a+1,r)):rest else (t, (a, r)) : addFilm title rest
  27.  
  28. insert:: Title -> Videolist -> (Videolist,Bool)
  29. insert title liste | not (hasFilm title liste)  = ((title, (1, 0)) : liste,False)
  30.                    | otherwise = (addFilm title liste,True)
  31.                    
  32. showVideolistItem::Title -> Videolist -> String
  33. showVideolistItem _ [] = "Film nicht in der Liste"
  34. showVideolistItem title ((t,(a,r)):rest) = if title ==  t
  35.                                                         then t ++ " (" ++ show r ++
  36.   " Exemplare verliehen, " ++
  37.     (if a == r then "keine" else show (a - r) ) ++ " Exemplare auf Lager)"
  38.                                                         else showVideolistItem title rest
  39.  
  40. state :: Videolist -> (Int, Int)
  41. state [] = (0,0)
  42. state ((_,(a,r)):rest) = ??
  43.  
  44. main::IO()
  45. main = do
  46.         putStr "search Am Limit"
Add Comment
Please, Sign In to add comment