[Haskell-cafe] Silly question: accessing a slot in a data type
Fernando Rodriguez
frr149 at easyjob.net
Wed Jan 9 10:32:38 EST 2008
Hi,
I'm writing a very simple address book. I defined the follwoing types for
Contact and AddressBook:
type Name= String
type PhoneNumber= Integer
data Contact = Contact {name :: Name, phone:: PhoneNumber} deriving Show
-- The addressBook is a lista of Contacts
data AddressBook= AddressBook [Contact] deriving Show
-- Create a test one
ag = Agenda [Contact "BillG" 618965332, Contact "Linus" 5897458]
I wan't to write a function to search for a given phone by name and return
a Maybe PhoneNumber. I know how to do this recursively on a "raw" list,
but how do I access the list inside AddressBook? Also, how do I represent
an AddressBook with an empty list and one with data on its list for my pattern
matching?
Thanks!
More information about the Haskell-Cafe
mailing list