mirror of
https://github.com/iritmaximus/haskell.git
synced 2026-10-12 19:13:39 +03:00
5a ex4
This commit is contained in:
+6
-6
@@ -66,28 +66,28 @@ buyOneMore (MkShoppingEntry name price amount) = MkShoppingEntry name price $ am
|
|||||||
-- Also define a Person value fred, and the functions getAge, getName,
|
-- Also define a Person value fred, and the functions getAge, getName,
|
||||||
-- setAge and setName (see below).
|
-- setAge and setName (see below).
|
||||||
|
|
||||||
data Person = PersonUndefined
|
data Person = Person Int String
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
-- fred is a person whose name is Fred and age is 90
|
-- fred is a person whose name is Fred and age is 90
|
||||||
fred :: Person
|
fred :: Person
|
||||||
fred = todo
|
fred = Person 90 "Fred"
|
||||||
|
|
||||||
-- getName returns the name of the person
|
-- getName returns the name of the person
|
||||||
getName :: Person -> String
|
getName :: Person -> String
|
||||||
getName p = todo
|
getName (Person _ name) = name
|
||||||
|
|
||||||
-- getAge returns the age of the person
|
-- getAge returns the age of the person
|
||||||
getAge :: Person -> Int
|
getAge :: Person -> Int
|
||||||
getAge p = todo
|
getAge (Person age _) = age
|
||||||
|
|
||||||
-- setName takes a person and returns a new person with the name changed
|
-- setName takes a person and returns a new person with the name changed
|
||||||
setName :: String -> Person -> Person
|
setName :: String -> Person -> Person
|
||||||
setName name p = todo
|
setName name (Person age _) = Person age name
|
||||||
|
|
||||||
-- setAge does likewise for age
|
-- setAge does likewise for age
|
||||||
setAge :: Int -> Person -> Person
|
setAge :: Int -> Person -> Person
|
||||||
setAge age p = todo
|
setAge age (Person _ name) = Person age name
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
-- Ex 5: define a datatype Position which contains two Int values, x
|
-- Ex 5: define a datatype Position which contains two Int values, x
|
||||||
|
|||||||
Reference in New Issue
Block a user