Fernando Rodriguez <[EMAIL PROTECTED]> wrote:
>
> 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!
like this:
manglePhone contact = contact { phone = ( 1 + phone contact ) }
--
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited.
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe