My problems are :
1. type Person = String
   type Book = String
   type Database = [(Person,Book)]
   exampleBase 
   = [("Alice", "Postmn Pat"),("Anna","All Alone"),("Alice","Spot")]
 
   books        :: Database -> Person -> [Book]
   borrowers    :: Database -> Book -> [Person]
   borrowed     :: Database -> Book -> [Bool]
   numBorrowed  :: Database -> Person -> Int

  books :: Database -> Person -> [Book]
  books [] borrowers = []
  books ((pers,bk):rest) borrowers
    |  pers == borrowers = bk : books rest borrower
    |  otherwise         =      books rest borrower

  {-output :
    books exampleBase "Alice" = ["Postman Pat","Spot"]
  -}

  borrowers :: Database -> Book -> [Person]
  borrowers [] books  = []
  borrowers ((pers,bk):rest) books
    | bk == books       = pers : borrowers rest books
    | otherwise         =        borrowers rest books

  {- output:
   books exampleBase "Spot" = ["Alice"]
  -}

  How should I do to  make borrowed and numBorrowed, because it's use
  String and integer, and i confuse.

2. type Name    = String
   type Price   = Int
   type BarCode = Int

   type Database = [(BarCode,Name,Price)]

   codeIndex :: Database
   codeIndex = [(4719, "Fish Fingers",121),
                (5643,"NAppies",1010),
                (3814,"Orange Jelly",56)]
 
   type TillType = [BarCode]
   type BillType = [(Name,Price)]

  How should I do to make function ?
        - makeBill :: TillType -> BillType
        - formatBill :: BillType -> String
        - printBill :: TillType -> String
  How should I defined BarCode to print (Name, Price)?

Thank's for your helping



Reply via email to