simple question

Cagdas Ozgenc co19@cornell.edu
Tue, 31 Jul 2001 11:57:39 +0300


Hi,

I am trying to do some exercies in my Haskell book. I couldn't get my
program to work correctly.

type Database2 = [ (Person,[ Book ]) ]

exampleBase2 :: Database2

exampleBase2 = [ ("Alice", [ "Tintin", "Astrix" ] ),

("Anna", [ "Little Woman" ] ),

("Rory", [ "Tintin" ] )

]

books2 :: Database2 -> Person -> [Book]

books2 db person = head [ snd tuple | tuple <- db, fst tuple == person ]

borrowers2 :: Database2 -> Book -> [Person]

borrowers2 db book = [ person | (person, books) <- db, book <- books ]



borrowers2 function should return the names of people that borrowed the
"book". However my implementation lists all the people. Book, and Person are
of type String. Also could you comment on the quality of the implementation
of  "books2" function, which is supposed to return the name of the books
that a person borrowed (It is working correctly).

Thanks