[Haskell-beginners] enumaratioin question
Leza Morais Lutonda
leza.ml at fecrd.cujae.edu.cu
Thu Feb 19 16:36:51 UTC 2015
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 at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
50 Aniversario de la Cujae. Inaugurada por Fidel el 2 de diciembre de 1964 http://cujae.edu.cu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150219/83599eb3/attachment.html>
More information about the Beginners
mailing list