Yes, "age p" gives the age of the person represented by "p".

On 19 February 2015 at 22:50, Roelof Wobben <r.wobben@home.nl> wrote:
Oke, I read that part.

Then I would be age p = ag

Roelof



Sumit Sahrawat, Maths & Computing, IIT (BHU) schreef op 19-2-2015 om 18:03:
When you use record syntax, accessors are automatically created for you. So,

data Person = Person {
      name     :: String
    , age      :: Integer
    , favThing :: String
    }

means that name, age and favThing are functions that do exactly what you want:

    name     :: Person -> String
    age      :: Person -> Integer
    favThing :: Person -> String

So you just need to call age on a Person value to get the age.
Due to this functionality, the names in record syntax can not start with an uppercase letter.

On 19 February 2015 at 22:27, Roelof Wobben <r.wobben@home.nl> wrote:
Thanks,

That is not what I mean ,

I mean this :

data Person = Person
      { name :: String ,
        Age :: Integer ,
        FavThing :: String  }


and i want to get the Age I could do this :

getAge (Person {age = ag}) = ag

Roelof


Sumit Sahrawat, Maths & Computing, IIT (BHU) schreef op 19-2-2015 om 17:37:
I can't understand what you mean by those colons in the second definition of Person. If you're thinking of type signatures, then that doesn't work in haskell.
In an ADT, you give names to possible values. So "Name String" will work whereas "Name : String" won't work.

data Person = Name String
            | Age Integer
            | FavThing String

means that Person can be one of these things (which is not what you want).

What you want is possible with record syntax. He'll detail it later I think.
If you're interested in learning about it beforehand, look it up in the haskell wikibook (another great haskell resource).


On 19 February 2015 at 21:58, Roelof Wobben <r.wobben@home.nl> 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




--
Regards

Sumit Sahrawat


_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners




--
Regards

Sumit Sahrawat


_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners




--
Regards

Sumit Sahrawat