Maybe you will want this:
data Person = Person {
name :: String,
age :: Int,
favThing :: String
}
And get the age:
getAge :: Person -> Int
getAge p = age p
Or better:
getAge = age
On 02/19/2015 11:28 AM, Roelof Wobben wrote:
Hello,
Im reading chapter 2 of the CIS 194 course about enumaratuin.
Now they give this example :
-- Store a person's name, age, and favourite Thing.
data Person = Person String Int Thing
deriving Show
brent :: Person
brent = Person "Brent" 31 SealingWax
stan :: Person
stan = Person "Stan" 94 Cabbage
getAge :: Person -> Int
getAge (Person _ a _) = a
I understand how this works.
But I wonder if there is no "better" way to get the Age.
Is it now wise to make a person data like this :
data Person = Name : String
| Age : Integer
| FavThing : String
And if so , how can I get the age then ?
Roelof
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners