Advertisement
Arina0904

lab3

Apr 19th, 2022 (edited)
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data Product = Books String String|Video String|Disk String String Int deriving Show
  2.  
  3. getTitle :: Product -> String
  4. getTitle (Books a b) = a
  5. getTitle (Video c) = c
  6. getTitle (Disk e f g) = e
  7.  
  8. getTitles :: [Product] -> [String]
  9. getTitles [] = []
  10. getTitles (x:xs) = getTitle x:getTitles xs
  11.  
  12. getAuthor :: Product -> String
  13. getAuthor (Books a b) = b
  14.  
  15. predBooks :: Product -> Bool
  16. predBooks (Books _ _) = True
  17. predBooks _ = False
  18.  
  19. getBooks = filter predBooks
  20.  
  21. getSome :: [Product] -> [String]
  22. getSome [] = []
  23. getSome ((Disk _ _ _):xs) = getSome xs
  24. getSome ((Video _):xs) = getSome xs
  25. getSome ((Books _ x):xs) = x:getSome xs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement