A
Frames test
> module Frames
> where
Define frame slots:
> type FirstName = String -- first name
> type LastName = String -- last name
> type Organization = String
> type Email = String
> type WorkPhone = String
> type CellPhone = String
> type TelephoneNumber = String
Define slots for a contact
> data ContactProperty = FN FirstName
> | LN LastName
> | OR Organization
> | EM Email
> | WP TelephoneNumber
> | MP TelephoneNumber
> deriving (Show, Eq)
> data Contact = Contact [ContactProperty]
> deriving (Show, Eq)
> type Contacts = [ Contact]
Now I need a way to extract properties from the frame. Start by testing
pattern matching
without using parameters. Then I need to find out how to pass a
constructor as a parameter.
> getProperty:: [ContactProperty] -> FirstName
> getProperty ((FN fn):_) = fn
> getProperty (_:xs) = getProperty xs
> getProperty [] = "unknown"
> firstName:: Contact -> FirstName
> firstName (Contact cpl) = getProperty cpl
Define Contacts
> c1::Contacts
> c1 =
> [ ( Contact [(FN "Ralph"),(LN "Hodgson"),(OR "TopQuadrant"),(EM
"rhodgson@topquadrant.com")]),
> ( Contact [(FN "Mills"),(LN "Davis"),(EM
"mdavis@project10x.com")])]
Tests
> t1=firstName $ head c1 -- should be "Ralph"
> t2=firstName $ last c1 -- should be "Mills"
___________________________