This commit is contained in:
Aaro Koivukangas
2025-12-22 22:21:09 +02:00
parent 2b1861a6b0
commit f7f38a745e
+6 -6
View File
@@ -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